php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #75693 ArrayObject does not set dynamic values up from 7.1.4
Submitted: 2017-12-15 17:12 UTC Modified: 2017-12-16 17:07 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:0 (0.0%)
From: kodeart at gmail dot com Assigned:
Status: Verified Package: SPL related
PHP Version: Irrelevant OS:
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: kodeart at gmail dot com
New email:
PHP Version: OS:

 

 [2017-12-15 17:12 UTC] kodeart at gmail dot com
Description:
------------
The dynamic key/values in ArrayObject are not set starting from v7.1.4 (up to 7.2.0) when the key does not exists and the value is array (nested or otherwise).

The overridden ArrayObject methods in the class exists to provide a fluid interface (for offsetSet) and return the value or NULL as a special case (for offsetGet). It's not the best logic but the behavior is expected to be consistent in all (or at least) PHP 7.1 versions.

Test script:
---------------
https://3v4l.org/LQdPJ

Expected result:
----------------
The behavior should be consistent in all versions.

Actual result:
--------------
At the time of this report the dynamic key/value is

- set in 5.6.0 - 5.6.30, 7.0.0 - 7.1.3
- not set up from 7.1.4 - 7.2.0 


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-12-16 17:07 UTC] nikic@php.net
-Status: Open +Status: Verified
 [2017-12-16 17:07 UTC] nikic@php.net
This is due to the fix for bug #74058. The problem is that your offsetGet() method simply wasn't called previously (for this specific code). Now it is called, but does not work correctly, because offsetGet() needs to return by reference to support indirect array modification. You'd need something like this instead: https://3v4l.org/ZofH7

Unfortunately this doesn't work either, because ArrayObject::offsetGet() itself does not return by reference. We can't easily change it to return by reference, because that would require all classes extending ArrayObject to do so as well, which would be a BC break.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 15:01:30 2024 UTC