php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #66641 ArrayObject doens't call offsetSet when using += with ARRAY_AS_PROPS flag
Submitted: 2014-02-04 14:16 UTC Modified: 2014-03-26 11:05 UTC
From: corentin dot larose at qapa dot com Assigned:
Status: Not a bug Package: SPL related
PHP Version: 5.4.24 OS: UBUNTU 12.04
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: corentin dot larose at qapa dot com
New email:
PHP Version: OS:

 

 [2014-02-04 14:16 UTC] corentin dot larose at qapa dot com
Description:
------------
ArrayObject doesn't call offsetSet when using combined operators on a property with \ArrayObject::ARRAY_AS_PROPS flag.

https://bugs.php.net/bug.php?id=45653&edit=2 says it should work.





Test script:
---------------
<?php
class MyArrayObject extends ArrayObject {
    public function offsetSet($name, $value) {
        parent::offsetSet($name . '_control', $value);
        parent::offsetSet($name, $value);
    }
}

$test = new MyArrayObject();
$test->setFlags(\ArrayObject::ARRAY_AS_PROPS);

$test['my_value_1']  = 1;
$test['my_value_1']  = $test['my_value_1'] + 1;
$test['my_value_1'] += 1;

$test->my_value_2  = 1;
$test->my_value_2  = $test->my_value_2 + 1;
$test->my_value_2 += 1; // It seems that MyArrayObject::offsetSet() is not called here

echo '<pre>';
print_r($test);


Expected result:
----------------
MyArrayObject Object
(
    [storage:ArrayObject:private] => Array
    (
        [my_value_1_control] => 3
        [my_value_1] => 3
        [my_value_2_control] => 3
        [my_value_2] => 3
    )
)

Actual result:
--------------
MyArrayObject Object
(
    [storage:ArrayObject:private] => Array
    (
        [my_value_1_control] => 3
        [my_value_1] => 3
        [my_value_2_control] => 2
        [my_value_2] => 3
    )
)

Patches

i.e.add-fronk-peter (last revision 2014-02-04 15:01 UTC by emily dot derek at yahoo dot com)

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-03-26 11:05 UTC] nikic@php.net
-Status: Open +Status: Not a bug
 [2014-03-26 11:05 UTC] nikic@php.net
This is an indirect modification of a property and as such goes through &offsetGet() rather than offsetSet().
 [2014-03-26 11:06 UTC] nikic@php.net
I meant &__get() and __set() there, of course.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Mon Jun 30 12:01:34 2025 UTC