ID: 38618 User updated by: mike at silverorange dot com Reported By: mike at silverorange dot com Status: Open Bug Type: SPL related Operating System: Linux PHP Version: 5.2.3 Assigned To: feedback asked New Comment:
I played around with the test case a bit more and it seems that the default RecursiveArrayIterator iterates the public properties of objects within the arrays. For example, if I adda public $foo = 'bar' property to the Fruit class, I get the following (incorrect) output: Default recursive array iteraration: title => apple foo => bar title => orange foo => bar title => banana foo => bar title => grape foo => bar title => peach foo => bar title => strawberry foo => bar title => grapefruit foo => bar Previous Comments: ------------------------------------------------------------------------ [2007-08-20 14:05:21] mike at silverorange dot com I tried changing the scope of the $title property from protected to public and the test case does indeed run correctly. Even so, the test case should still run correctly when the property is protected. ------------------------------------------------------------------------ [2007-08-20 10:34:33] [EMAIL PROTECTED] Replace "protected" with "public" and it works fine.. ------------------------------------------------------------------------ [2007-07-02 15:03:09] mike at silverorange dot com Sorray about that. Try this link: http://labs.silverorange.com/local/solabs/include/recursive-array-iterator.txt ------------------------------------------------------------------------ [2007-06-28 01:51:27] mike at silverorange dot com This bug still exists in PHP 5.2.3 using the same test script as before. ------------------------------------------------------------------------ [2006-08-27 22:10:35] mike at silverorange dot com Description: ------------ The default implementation of hasChildren() in RecursiveArrayIterator does not work if the recursive array contains object references. If I subclass the RecursiveArrayIterator and re-implement the method exactly as it is in the source code everything is fine. If I use the default implementation, the objects in my array do not get iterated. Inside my re-implemented hasChildren() method if I call parent::hasChildren() it returns 1 when $this->current() is an object. Reproduce code: --------------- Code to reproduce: http://wiki.silverorange.com/Recursive_Array_Iterator Expected result: ---------------- Expected output from reproduce code: Default recursive array iteraration: 1 => apple 2 => orange 3 => banana 1 => grape 2 => peach 3 => strawberry 4 => grapefruit Reimplemented hasChildren() recursive array iteraration: 1 => apple 2 => orange 3 => banana 1 => grape 2 => peach 3 => strawberry 4 => grapefruit Default recursive array iteraration: 1 => apple 2 => orange 3 => banana 1 => grape 2 => peach 3 => strawberry 4 => grapefruit Reimplemented hasChildren() recursive array iteraration: 1 => apple 2 => orange 3 => banana 1 => grape 2 => peach 3 => strawberry 4 => grapefruit Actual result: -------------- Output from reproduce code: Default recursive array iteraration: 1 => apple 2 => orange 3 => banana 1 => grape 2 => peach 3 => strawberry 4 => grapefruit Reimplemented hasChildren() recursive array iteraration: 1 => apple 2 => orange 3 => banana 1 => grape 2 => peach 3 => strawberry 4 => grapefruit Default recursive array iteraration: Reimplemented hasChildren() recursive array iteraration: 1 => apple 2 => orange 3 => banana 1 => grape 2 => peach 3 => strawberry 4 => grapefruit ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=38618&edit=1