php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #77633 Preloading incompatible with ArrayItertor inheritance
Submitted: 2019-02-18 10:48 UTC Modified: -
From: nikic@php.net Assigned:
Status: Closed Package: Scripting Engine problem
PHP Version: master-Git-2019-02-18 (Git) OS:
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: nikic@php.net
New email:
PHP Version: OS:

 

 [2019-02-18 10:48 UTC] nikic@php.net
Description:
------------
When extending an ArrayIterator, the get_iterator handler is overridden with spl_array_get_iterator **during object construction**: https://github.com/php/php-src/blob/8ee78441f87d59f22c2e6865a31e87f5076500da/ext/spl/spl_array.c#L211

This is incompatible with preloading, as the class is immutable at this point.

We can't simply remove the assignment, because this would break by-ref iteration of objects extending ArrayIterator.

Another way to handle this would be to inherit get_iterator in the interface_gets_implemented handlers for Iterator/IteratorAggregate. Unfortunately this also doesn't work, because some code (e.g. RecursiveIteratorIterator) assumes that the user get_iterator handler will be used if the class is inherited (it does not deal with overridden iterator methods).

Test script:
---------------
<?php
class Foo extends ArrayIterator {}
new Foo([]);


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2019-02-18 12:59 UTC] nikic@php.net
Automatic comment on behalf of dmitry@zend.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=c9ffae1bec67d628d2859368be66175b5c693de5
Log: Fixed bug #77633
 [2019-02-18 12:59 UTC] nikic@php.net
-Status: Open +Status: Closed
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed May 14 15:01:28 2025 UTC