#48205 [Ver->Bgs]: RecursiveIteratorIterator->callGetChildren() raises InvalidArgumentException
| From: | colder@php.net | Date: | Sat, 09 May 2009 20:36:19 +0000 |
| Subject: | #48205 [Ver->Bgs]: RecursiveIteratorIterator->callGetChildren() raises InvalidArgumentException | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-137051@lists.php.net to get a copy of this message | ||
ID: 48205
Updated by: colder@php.net
Reported By: sean at practicalweb dot co dot uk
-Status: Verified
+Status: Bogus
Bug Type: SPL related
Operating System: *
PHP Version: 5.*, 6CVS (2009-05-09)
New Comment:
That's expected, callGetChildren will call
RecursiveArrayIterator::getChildren when the current element is an
integer. getChildren will then instantiate an ArrayIterator object, and
pass the current element as argument, resulting in an exception since
it's not an array or an object.
Previous Comments:
------------------------------------------------------------------------
[2009-05-09 19:18:42] jani@php.net
Please, when you do testing, test with PHP_5_2 also and HEAD. And set
the version string like I did now in case the bug exists in all
branches..
------------------------------------------------------------------------
[2009-05-09 13:52:57] sean at practicalweb dot co dot uk
Description:
------------
If the current element of a RecursiveIteratorIterator has no children
then callGetChildren() causes an error message like
Fatal error: Uncaught exception 'InvalidArgumentException' with message
'Passed variable is not an array or object, using empty array instead'
This is confusing because the PHP code does not pass an argument here.
I think that either the method should return null when there are no
children - or at least the error message could be clearer.
This has been found as part of phptestfest 09 - an XFail test will be
commited from PHPLondon
My Apologies if this is expected behaviour, I realise the code is
undocumented, but I wanted to commit a test to cover this and filing a
bug seemed the best way to confirm one way or the other :-)
Reproduce code:
---------------
<?php
$array = array(array(7,8,9),1,2,3,array(4,5,6));
$recursiveArrayIterator = new RecursiveArrayIterator($array);
$test = new RecursiveIteratorIterator($recursiveArrayIterator);
var_dump($test->current());
$test->next();
var_dump($test->current());
try {
$output = $test->callGetChildren();
} catch (InvalidArgumentException $ilae){
$output = null;
print "invalid argument exception\n";
}
var_dump($output);
?>
Expected result:
----------------
array(3) {
[0]=>
int(7)
[1]=>
int(8)
[2]=>
int(9)
}
int(7)
NULL
Actual result:
--------------
array(3) {
[0]=>
int(7)
[1]=>
int(8)
[2]=>
int(9)
}
int(7)
invalid argument exception
NULL
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=48205&edit=1