Edit report at https://bugs.php.net/bug.php?id=76354&edit=1
ID: 76354
Updated by: [email protected]
Reported by: biser dot antonov at gmail dot com
Summary: ArrayObject doesn't call the constructor of a custom
iterator when foreach
Status: Open
-Type: Bug
+Type: Documentation Problem
Package: SPL related
Operating System: Debian
PHP Version: 7.2.5
Block user comment: N
Private report: N
New Comment:
Well, only constructors without any mandatory parameters could be
successfully called anyway, since there is no way to specify the
arguments.
Anyhow, given the long standing behavior, and that it is
apparently a design decision, I'm switching to documentation
problem.
Previous Comments:
------------------------------------------------------------------------
[2018-05-18 07:18:36] biser dot antonov at gmail dot com
Description:
------------
When providing a custom iterator to an ArrayObject, the iterator's constructor is not called on foreach.
Tested in the official php docker container:
https://github.com/docker-library/php/blob/b045ba7c51ceed8a495beb8ea7274df48a3c70e1/7.2/stretch/cli/Dockerfile
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
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=76354&edit=1
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.