Bug #75942 [Opn]: Backward incompatibility introduced in RecursiveArrayIterator
| From: | nikic@php.net | Date: | Fri, 09 Feb 2018 08:46:08 +0000 |
| Subject: | Bug #75942 [Opn]: Backward incompatibility introduced in RecursiveArrayIterator | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-213884@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=75942&edit=1
ID: 75942
Updated by: nikic@php.net
Reported by: andries at centim dot be
Summary: Backward incompatibility introduced in
RecursiveArrayIterator
Status: Open
Type: Bug
Package: SPL related
Operating System: any
PHP Version: 7.1.14
Block user comment: N
Private report: N
New Comment:
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.
Previous Comments:
------------------------------------------------------------------------
[2018-02-09 07:56:20] 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
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=75942&edit=1