Bug #76354 [NEW]: ArrayObject doesn't call the constructor of a custom iterator when foreach
| From: | biser dot antonov at gmail dot com | Date: | Fri, 18 May 2018 07:18:38 +0000 |
| Subject: | Bug #76354 [NEW]: ArrayObject doesn't call the constructor of a custom iterator when foreach | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-215295@lists.php.net to get a copy of this message | ||
From: biser dot antonov at gmail dot com
Operating system: Debian
PHP version: 7.2.5
Package: SPL related
Bug Type: Bug
Bug description:ArrayObject doesn't call the constructor of a custom iterator when foreach
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 bug report at https://bugs.php.net/bug.php?id=76354&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=76354&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=76354&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=76354&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=76354&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=76354&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=76354&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=76354&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=76354&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=76354&r=support
Expected behavior: https://bugs.php.net/fix.php?id=76354&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=76354&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=76354&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=76354&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=76354&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=76354&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=76354&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=76354&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=76354&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=76354&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=76354&r=mysqlcfg