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
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.
(description)
Block user comment
Status: Assign to:
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

Add a Patch

Pull Requests

Add a Pull Request

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-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 16 08:01:32 2024 UTC