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

From: Date: Thu, 08 Feb 2018 14:24:55 +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-213866@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:         andries at centim dot be
 Reported by:        sfyire at gmail dot com
 Summary:            RecursiveArrayIterator does not iterate object
                     properties
 Status:             Closed
 Type:               Bug
 Package:            SPL related
 Operating System:   ubuntu
 PHP Version:        7.0.11
 Block user comment: N
 Private report:     N

 New Comment:

It seems that this fix caused a BC break from php 7.1.13. See the following gist on how to
reproduce: https://gist.github.com/andriesss/b22b4057bd7e0563f4d21b7b2cfd6a09


Previous Comments:
------------------------------------------------------------------------
[2017-12-22 17:23:15] nikic@php.net

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

------------------------------------------------------------------------
[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)

« previous php.bugs (#213866) next »