|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #76354 ArrayObject doesn't call the constructor of a custom iterator when foreach
Submitted: 2018-05-18 07:18 UTC Modified: -
From: biser dot antonov at gmail dot com Assigned:
Status: Open Package: SPL related
PHP Version: 7.2.5 OS: Debian
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.
Block user comment
Status: Assign to:
Bug Type:
From: biser dot antonov at gmail dot com
New email:
PHP Version: OS:


 [2018-05-18 07:18 UTC] biser dot antonov at gmail dot com
When providing a custom iterator to an ArrayObject, the iterator's constructor is not called on foreach.

Tested in the official php docker container:

Test script:
class I extends ArrayIterator
    public function __construct(array $array = array(), $flags = 0)
        exit(__FILE__ . ':' . __LINE__);

$a = new ArrayObject([1, 2, 3], 0, I::class);
foreach ($a as $key => $value) {
    // do something

Expected result:
I expected the script to call I::__construct() and exit

Actual result:
The script finished without interruption 


Add a Patch

Pull Requests

Add a Pull Request

PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Wed Jul 28 04:01:25 2021 UTC