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:2
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 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: andries at centim dot be
New email:
PHP Version: OS:

 

 [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

Pull Requests

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-2024 The PHP Group
All rights reserved.
Last updated: Fri Oct 04 20:01:28 2024 UTC