Bug #78356 [Opn->Csd]: Array returned from ArrayAccess is incorrectly unpacked as argument
| From: | nikic@php.net | Date: | Thu, 01 Aug 2019 08:14:04 +0000 |
| Subject: | Bug #78356 [Opn->Csd]: Array returned from ArrayAccess is incorrectly unpacked as argument | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-222036@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=78356&edit=1
ID: 78356
Updated by: nikic@php.net
Reported by: esurov dot tsp at gmail dot com
Summary: Array returned from ArrayAccess is incorrectly
unpacked as argument
-Status: Open
+Status: Closed
Type: Bug
Package: Scripting Engine problem
Operating System: Ubuntu
PHP Version: 7.4Git-2019-07-31 (snap)
-Assigned To:
+Assigned To: nikic
Block user comment: N
Private report: N
New Comment:
I don't see a good way to fix both issues at the same time, so I'm restoring previous
behavior...
Reverted in https://github.com/php/php-src/commit/afd96392a344f1b2a8aac2be375293b47f633ca4
and test added in https://github.com/php/php-src/commit/bab8b3a8bef4b5fd5c3fe75ebb1c231614ef3cfa.
Previous Comments:
------------------------------------------------------------------------
[2019-07-31 15:24:46] nikic@php.net
The issue here is basically that ...$object[0] *might* want to modify $object[0] and the
aforementioned commit actually makes that work -- unfortunately it emits this bogus notice in the
case where we don't actually want to do the modification.
------------------------------------------------------------------------
[2019-07-31 12:45:46] cmb@php.net
To clarify: this is a notice by default, not an error. Anyhow,
this behavioral change has been introduced with commit 6913ec3[1].
[1] <http://git.php.net/?p=php-src.git;a=commit;h=6913ec3282149914e999d91b056fe1cc68d15ed7>
------------------------------------------------------------------------
[2019-07-31 10:56:39] esurov dot tsp at gmail dot com
Description:
------------
Let some object implements ArrayAccess and its offsetGet() returns an array. Then if we use the
accessed result as an unpacked (with ... token) argument we're getting an error: Indirect
modification of overloaded element of class@anonymous has no effect.
Test script:
---------------
$object = new class implements ArrayAccess {
public function offsetGet($offset)
{
return [1, 2];
}
public function offsetExists($offset)
{
return true;
}
public function offsetUnset($offset) {}
public function offsetSet($offset, $value) {}
};
$x = max(...$object[0]);
Expected result:
----------------
$x contains 2.
Actual result:
--------------
Error: Indirect modification of overloaded element of class@anonymous has no effect
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=78356&edit=1