|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #78356 Array returned from ArrayAccess is incorrectly unpacked as argument
Submitted: 2019-07-31 10:56 UTC Modified: 2019-08-01 08:14 UTC
From: esurov dot tsp at gmail dot com Assigned: nikic (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: 7.4Git-2019-07-31 (snap) OS: Ubuntu
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: esurov dot tsp at gmail dot com
New email:
PHP Version: OS:


 [2019-07-31 10:56 UTC] esurov dot tsp at gmail dot com
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


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2019-07-31 12:45 UTC]
-Package: SPL related +Package: Scripting Engine problem
 [2019-07-31 12:45 UTC]
To clarify: this is a notice by default, not an error.  Anyhow,
this behavioral change has been introduced with commit 6913ec3[1].

[1] <;a=commit;h=6913ec3282149914e999d91b056fe1cc68d15ed7>
 [2019-07-31 15:24 UTC]
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-08-01 08:14 UTC]
-Status: Open +Status: Closed -Assigned To: +Assigned To: nikic
 [2019-08-01 08:14 UTC]
I don't see a good way to fix both issues at the same time, so I'm restoring previous behavior...

Reverted in and test added in
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Sat Oct 23 15:03:34 2021 UTC