Bug #73209 [Com]: RecursiveArrayIterator does not iterate object properties

From: Date: Fri, 11 Aug 2017 07:34:43 +0000
Subject: Bug #73209 [Com]: RecursiveArrayIterator does not iterate object properties
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-210595@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=73209&edit=1

 ID:                 73209
 Comment by:         j_fiel at yahoo dot com
 Reported by:        sfyire at gmail dot com
 Summary:            RecursiveArrayIterator does not iterate object
                     properties
 Status:             Open
 Type:               Bug
 Package:            SPL related
 Operating System:   ubuntu
 PHP Version:        7.0.11
 Block user comment: N
 Private report:     N

 New Comment:

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
  }
}


Previous Comments:
------------------------------------------------------------------------
[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)

« previous php.bugs (#210595) next »