Bug #77633 [Opn->Csd]: Preloading incompatible with ArrayItertor inheritance

From: Date: Mon, 18 Feb 2019 12:59:13 +0000
Subject: Bug #77633 [Opn->Csd]: Preloading incompatible with ArrayItertor inheritance
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-219627@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=77633&edit=1 ID: 77633 Updated by: nikic@php.net Reported by: nikic@php.net Summary: Preloading incompatible with ArrayItertor inheritance -Status: Open +Status: Closed Type: Bug Package: Scripting Engine problem PHP Version: master-Git-2019-02-18 (Git) Block user comment: N Private report: N New Comment: 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 Previous Comments: ------------------------------------------------------------------------ [2019-02-18 10:48:06] 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([]); ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=77633&edit=1

« previous php.bugs (#219627) next »