php.net |  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 you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
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
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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2019-07-31 12:45 UTC] cmb@php.net
-Package: SPL related +Package: Scripting Engine problem
 [2019-07-31 12:45 UTC] 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 15:24 UTC] 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-08-01 08:14 UTC] nikic@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: nikic
 [2019-08-01 08:14 UTC] nikic@php.net
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.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Fri Jan 31 06:01:31 2025 UTC