function rewind()
    {
        echo "<ul>\n";
        parent::rewind();
    }
    function beginChildren()
    {
        echo str_repeat('  ', $this->getDepth()) . "<ul>\n";
    }
    function endChildren()
    {
        echo str_repeat('  ', $this->getDepth()) . "</ul>\n";
    }
    function valid()
    {
        if (!parent::valid()) {
            echo "<ul>\n";
            return false;
        }
        return true;
    }
}
$arr = array("a", array("ba", array("bba", "bbb"), array(array("bcaa"))), array("ca"), "d");
$obj = new RecursiveArrayIterator($arr);
$rit = new RecursiveArrayIteratorIterator($obj);
foreach ($rit as $k => $v) {
    echo str_repeat('  ', $rit->getDepth() + 1) . "{$k}=>{$v}\n";
}
?>
===DONE===
Ejemplo n.º 2
0
<?php

$count = 10;
class RecursiveArrayIteratorIterator extends RecursiveIteratorIterator
{
    function rewind()
    {
        echo "dummy\n";
    }
    function endChildren()
    {
        global $count;
        echo $this->getDepth();
        if (--$count > 0) {
            // Trigger use-after-free
            parent::rewind();
        }
    }
}
$arr = array("a", array("ba", array("bba", "bbb")));
$obj = new RecursiveArrayIterator($arr);
$rit = new RecursiveArrayIteratorIterator($obj);
foreach ($rit as $k => $v) {
    echo $rit->getDepth() . "{$k}=>{$v}\n";
}
        echo __METHOD__ . "(" . $this->getDepth() . ") = " . ($res ? "yes" : "no") . "/" . ($has ? "yes" : "no") . "\n";
        return $res;
    }
    function beginChildren()
    {
        echo __METHOD__ . "(" . $this->getDepth() . ")\n";
        parent::beginChildren();
    }
    function endChildren()
    {
        echo __METHOD__ . "(" . $this->getDepth() . ")\n";
        parent::endChildren();
    }
}
$p = 0;
$it = new RecursiveArrayIteratorIterator(new MyRecursiveArrayIterator(array("a", array("ba", array("bba", "bbb"), array(array("bcaa"), array("bcba"))), array("ca"), "d")), 2);
foreach ($it as $k => $v) {
    if (is_array($v)) {
        $v = join('', $v);
    }
    echo "{$k}=>{$v}\n";
    if ($p++ == 5) {
        echo "===BREAK===\n";
        break;
    }
}
echo "===FOREND===\n";
$it->rewind();
echo "===CHECK===\n";
var_dump($it->valid());
var_dump($it->current() == "a");
Ejemplo n.º 4
0
<?php

class RecursiveArrayIteratorIterator extends RecursiveIteratorIterator
{
    function rewind()
    {
        echo __METHOD__ . " called \n";
        parent::rewind();
    }
    function beginChildren()
    {
        echo __METHOD__ . " called \n";
    }
    function endChildren()
    {
        echo __METHOD__ . " called \n";
    }
}
$arr = array("a", array("ca"));
$obj = new RecursiveArrayIterator($arr);
$rit = new RecursiveArrayIteratorIterator($obj);
echo "Rewind: \n";
$rit->rewind();
echo "\nNext:\n";
$rit->next();
$rit->next();
?>
===DONE===
<?php 
exit(0);