|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #75942 Backward incompatibility introduced in RecursiveArrayIterator
Submitted: 2018-02-09 07:56 UTC Modified: 2018-02-09 08:46 UTC
Avg. Score:4.5 ± 0.5
Reproduced:2 of 2 (100.0%)
Same Version:0 (0.0%)
Same OS:2 (100.0%)
From: andries at centim dot be Assigned:
Status: Open Package: SPL related
PHP Version: 7.1.14 OS: any
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: andries at centim dot be
New email:
PHP Version: OS:


 [2018-02-09 07:56 UTC] andries at centim dot be
I'm referencing to ticket that was fixed in PHP 7.1.14, and seems to have introduced a backward compatibility issue compared to PHP 7.1.13. I'm creating a new ticket, as this ticket was already closed.

When RecursiveArrayIterator is used in combination with a RecursiveIteratorIterator, and your class has a public property that contains a DateTime instance, it will crash with the following error: Overloaded object of type DateTime is not compatible with RecursiveArrayIterator

This did not produce an error on PHP 7.1.13, 

Was it a bug that it didn't iterate object properties? Or is supporting it a new feature? I lean toward the latter without having seen the spec, but either way the current fix breaks backward compatibility. 

Test script:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2018-02-09 08:46 UTC]
The fix for bug #73209 restores the behavior of PHP 5.x, which was accidentally broken during the migration to PHP 7. This is definitely a bug, in particular because previously behavior would differ based on whether or not the property was declared. If it was not declared, the properties would have already been iterated and you'd already see the error. Due to the aforementioned migration issue, the same did not happen for declared object properties.

RecursiveArrayIterator has an option CHILD_ARRAYS_ONLY to limit recursion to arrays only.

One potential change we could make here is to not try to iterate overloaded objects in RecursiveArrayIterator, thus also avoiding the exception. I think this exception is more intended for ArrayIterator and it might be better to just skip unsupported objects in RecursiveArrayIterator.
 [2018-02-13 09:17 UTC] andries at centim dot be
Which objects are unsupported objects? I tried it with a couple of other internal classes (Exception, stdClass), but could not reproduce the error with those.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon May 20 21:01:34 2024 UTC