Bug #76921 [NEW]: ArrayAccess only supports increment on by-ref offsetGet()

From: Date: Sun, 23 Sep 2018 14:11:13 +0000
Subject: Bug #76921 [NEW]: ArrayAccess only supports increment on by-ref offsetGet()
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-217206@lists.php.net to get a copy of this message
From: nikic Operating system: PHP version: Irrelevant Package: Scripting Engine problem Bug Type: Bug Bug description:ArrayAccess only supports increment on by-ref offsetGet() Description: ------------ Overloaded properties implement $x->y++ by calling __set('y', __get('y') + 1). The same does not work for ArrayAccess. ArrayAccess only supports $x[0]++ if offsetGet() returns by reference, in which case the increment is performed on the reference. This is inconsistent both with the overloaded property behavior and with compound assignment operations on ArrayAccess. That is, $x[0] += 1 *does* work with a by-value offsetGet(). Test script: --------------- <?php class Test implements ArrayAccess { public function __get($k) { return 1; } public function __set($k, $v) { echo "__set($v)\n"; } public function offsetGet($k) { return 1; } public function offsetSet($k, $v) { echo "offsetSet($v)\n"; } public function offsetExists($k) {} public function offsetUnset($k) {} } $t = new Test; echo "Property:\n"; $t->x++; echo "Offset:\n"; $t[0]++; Expected result: ---------------- Property: __set(2) Offset: offsetSet(2) Actual result: -------------- Property: __set(2) Offset: Notice: Indirect modification of overloaded element of Test has no effect -- Edit bug report at https://bugs.php.net/bug.php?id=76921&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=76921&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=76921&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=76921&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=76921&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=76921&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=76921&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=76921&r=needscript Try newer version: https://bugs.php.net/fix.php?id=76921&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=76921&r=support Expected behavior: https://bugs.php.net/fix.php?id=76921&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=76921&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=76921&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=76921&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=76921&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=76921&r=dst IIS Stability: https://bugs.php.net/fix.php?id=76921&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=76921&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=76921&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=76921&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=76921&r=mysqlcfg

« previous php.bugs (#217206) next »