Bug #78356 [Opn]: Array returned from ArrayAccess is incorrectly unpacked as argument

From: Date: Wed, 31 Jul 2019 15:24:46 +0000
Subject: Bug #78356 [Opn]: Array returned from ArrayAccess is incorrectly unpacked as argument
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-222027@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 Type: Bug Package: Scripting Engine problem Operating System: Ubuntu PHP Version: 7.4Git-2019-07-31 (snap) Block user comment: N Private report: N New Comment: 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. Previous Comments: ------------------------------------------------------------------------ [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

« previous php.bugs (#222027) next »