Find this useful? Enter your email to receive occasional updates for securing PHP code.

Signing you up...

Thank you for signing up!

PHP Decode

--TEST-- SPL: RecursiveIteratorIterator - Exception thrown in beginchildren which should b..

Decoded Output download

--TEST--
SPL: RecursiveIteratorIterator - Exception thrown in beginchildren which should be handled in next()
--FILE--
<?php

$arr = array(array(1,2),2);
$arrOb = new ArrayObject($arr);

$recArrIt = new RecursiveArrayIterator($arrOb->getIterator());

class MyRecursiveIteratorIterator extends RecursiveIteratorIterator {

    function beginchildren(): void {
        throw new Exception;
    }
}


$recItIt = new MyRecursiveIteratorIterator($recArrIt, RecursiveIteratorIterator::LEAVES_ONLY, RecursiveIteratorIterator::CATCH_GET_CHILD);

var_dump($recItIt->next());

$recItIt2 = new MyRecursiveIteratorIterator($recArrIt, RecursiveIteratorIterator::LEAVES_ONLY);

var_dump($recItIt2->next());

?>
--EXPECTF--
NULL

Fatal error: Uncaught Exception in %s
Stack trace:
#0 [internal function]: MyRecursiveIteratorIterator->beginchildren()
#1 %s: RecursiveIteratorIterator->next()
#2 {main}
  thrown in %s on line %d

Did this file decode correctly?

Original Code

--TEST--
SPL: RecursiveIteratorIterator - Exception thrown in beginchildren which should be handled in next()
--FILE--
<?php

$arr = array(array(1,2),2);
$arrOb = new ArrayObject($arr);

$recArrIt = new RecursiveArrayIterator($arrOb->getIterator());

class MyRecursiveIteratorIterator extends RecursiveIteratorIterator {

    function beginchildren(): void {
        throw new Exception;
    }
}


$recItIt = new MyRecursiveIteratorIterator($recArrIt, RecursiveIteratorIterator::LEAVES_ONLY, RecursiveIteratorIterator::CATCH_GET_CHILD);

var_dump($recItIt->next());

$recItIt2 = new MyRecursiveIteratorIterator($recArrIt, RecursiveIteratorIterator::LEAVES_ONLY);

var_dump($recItIt2->next());

?>
--EXPECTF--
NULL

Fatal error: Uncaught Exception in %s
Stack trace:
#0 [internal function]: MyRecursiveIteratorIterator->beginchildren()
#1 %s: RecursiveIteratorIterator->next()
#2 {main}
  thrown in %s on line %d

Function Calls

None

Variables

None

Stats

MD5 bc874f8e3966b9b9ef2ac7259810f9f3
Eval Count 0
Decode Time 92 ms