Bug #76355 [NEW]: ArrayObject allows foreach by reference
| From: | biser dot antonov at gmail dot com | Date: | Fri, 18 May 2018 07:40:04 +0000 |
| Subject: | Bug #76355 [NEW]: ArrayObject allows foreach by reference | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-215296@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 allows foreach by reference
Description:
------------
I don't know if it's bug but the ArrayObject allows foreach by
reference.
If however I create it with a custom iterator which overrides the
current() method a fatal error is produced:
Fatal error: An iterator cannot be used with foreach by reference
Links with both cases can be found here:
https://3v4l.org/aBKtd
https://3v4l.org/00Z3F
Test script:
---------------
$a = new ArrayObject([1, 2, 3]);
foreach ($a as $key => &$value) {
$value += 10;
}
unset($value);
var_dump($a);
Expected result:
----------------
Fatal error: An iterator cannot be used with foreach by reference
Actual result:
--------------
object(ArrayObject)#1 (1) {
["storage":"ArrayObject":private]=>
array(3) {
[0]=>
int(11)
[1]=>
int(12)
[2]=>
int(13)
}
}
--
Edit bug report at https://bugs.php.net/bug.php?id=76355&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=76355&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=76355&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=76355&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=76355&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=76355&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=76355&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=76355&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=76355&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=76355&r=support
Expected behavior: https://bugs.php.net/fix.php?id=76355&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=76355&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=76355&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=76355&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=76355&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=76355&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=76355&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=76355&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=76355&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=76355&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=76355&r=mysqlcfg