#38618 [Asn->NoF]: default implementation of hasChildren() in RecursiveArrayIterator does not work

From: Date: Thu, 15 May 2008 23:23:28 +0000
Subject: #38618 [Asn->NoF]: default implementation of hasChildren() in RecursiveArrayIterator does not work
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-125038@lists.php.net to get a copy of this message
ID: 38618 Updated by: colder@php.net Reported By: mike at silverorange dot com -Status: Assigned +Status: No Feedback Bug Type: SPL related Operating System: * PHP Version: 5.2.5 -Assigned To: helly +Assigned To: colder New Comment: I MFB'ed that patch to HEAD as well with a slight distinction, The constant now belongs to RecursiveArrayIterator, and not ArrayObject anymore. This flag is off by default. Previous Comments: ------------------------------------------------------------------------ [2007-12-05 16:00:40] helly@php.net So far the behavior is expected as ArrayObject/ArrayIterator follow arrays as well as objects. For 5.3 I added a new flag ArrayObject::CHILD_ARRAYS_ONLY that can be used to prevent ArrayIterator from following objects. IF you feel this is ok let me know. If you think the behavior should be reverse, meaning the flag should be active by default and there should be a way to disable it then open a RFC on internals@php.net. ------------------------------------------------------------------------ [2007-08-20 15:01:23] jani@php.net Marcus, can you check this out please? ------------------------------------------------------------------------ [2007-08-20 14:14:53] mike at silverorange dot com 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 ------------------------------------------------------------------------ [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] jani@php.net Replace "protected" with "public" and it works fine.. ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at http://bugs.php.net/38618 -- Edit this bug report at http://bugs.php.net/?id=38618&edit=1

« previous php.bugs (#125038) next »