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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
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)

Add a Patch

Pull Requests

Add a Pull Request

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-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 09:01:26 2024 UTC