|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2016-09-30 09:32 UTC] 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 PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Oct 30 22:00:01 2025 UTC |
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 } }