php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #73209 RecursiveArrayIterator does not iterate object properties
Submitted: 2016-09-30 09:32 UTC Modified: -
Votes:1
Avg. Score:1.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: sfyire at gmail dot com Assigned:
Status: Closed Package: SPL related
PHP Version: 7.0.11 OS: ubuntu
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: sfyire at gmail dot com
New email:
PHP Version: OS:

 

 [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


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-08-11 07:34 UTC] 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
  }
}
 [2017-12-22 17:23 UTC] 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-12-22 17:23 UTC] nikic@php.net
-Status: Open +Status: Closed
 [2018-02-08 14:24 UTC] andries at centim dot be
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
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Oct 08 21:01:27 2024 UTC