Bug #73209 [Opn->Csd]: RecursiveArrayIterator does not iterate object properties
Edit report at https://bugs.php.net/bug.php?id=73209&edit=1
ID: 73209
Updated by: nikic@php.net
Reported by: sfyire at gmail dot com
Summary: RecursiveArrayIterator does not iterate object
properties
-Status: Open
+Status: Closed
Type: Bug
Package: SPL related
Operating System: ubuntu
PHP Version: 7.0.11
Block user comment: N
Private report: N
New Comment:
Automatic comment on behalf of nikita.ppv@gmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=f14b6f49209b360018224aec38e8ea94fcf3dbf4
Log: Fixed bug #73209
Previous Comments:
------------------------------------------------------------------------
[2017-08-11 07:34:38] j_fiel at yahoo dot com
I also had this problem.
I am using Debian 9.1 and PHP 7.1.8.
Here is some sample code to reproduce the problem:
----------
class topClass
{
public $status;
public $baseRef;
}
class nestedClass1
{
public $statusDetail;
public $isSuccess = 1;
}
class nestedClass2
{
public $internalId = 1;
public $externalId = 3;
public $typeId = 10;
public $name;
}
$testObject = new topClass();
$testObject->status = new nestedClass1();
$testObject->baseRef = new nestedClass2();
$flatObject = new stdClass();
$iterator = new RecursiveIteratorIterator(
new RecursiveArrayIterator($testObject)
);
foreach ($iterator as $key => $value) {
$flatObject->$key = $value;
}
var_dump($flatObject);
----------
This is the result with the versions I tested.
PHP 5.2.17 and also 5.4.45:
object(stdClass)#99 (6) {
["statusDetail"]=>
NULL
["isSuccess"]=>
int(1)
["internalId"]=>
int(1)
["externalId"]=>
int(3)
["typeId"]=>
int(10)
["name"]=>
NULL
}
PHP 7.1.8:
object(stdClass)#99 (2) {
["status"]=>
object(nestedClass1)#97 (2) {
["statusDetail"]=>
NULL
["isSuccess"]=>
int(1)
}
["baseRef"]=>
object(nestedClass2)#98 (4) {
["internalId"]=>
int(1)
["externalId"]=>
int(3)
["typeId"]=>
int(10)
["name"]=>
NULL
}
}
------------------------------------------------------------------------
[2016-09-30 09:32:11] sfyire at gmail dot com
Description:
------------
The problem I have observed is that in PHP7 and up RecursiveArrayIterator stops
iterating arrays that are object properties
However if I implement a class that has the exact same source code as RecursiveArrayIterator (taken
from here: http://fossies.org/dox/php-7.0.11-src/recursivearrayiterator_8inc_source.html)
and use that instead then object property arrays are iterated correctly.
Test script:
---------------
https://3v4l.org/DO2SA
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=73209&edit=1
Thread (4 messages)