php.net |  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
Votes:1
Avg. Score:4.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:1 (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
Have you experienced this issue?
Rate the importance of this bug to you:

 [2018-02-09 07:56 UTC] andries at centim dot be
Description:
------------
I'm referencing to ticket https://bugs.php.net/bug.php?id=73209 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:
---------------
https://gist.github.com/andriesss/b22b4057bd7e0563f4d21b7b2cfd6a09


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-02-09 08:46 UTC] nikic@php.net
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-2019 The PHP Group
All rights reserved.
Last updated: Wed Oct 23 02:01:31 2019 UTC