Bug #66641 [Opn->Nab]: ArrayObject doens't call offsetSet when using += with ARRAY_AS_PROPS flag

From: Date: Wed, 26 Mar 2014 11:05:43 +0000
Subject: Bug #66641 [Opn->Nab]: ArrayObject doens't call offsetSet when using += with ARRAY_AS_PROPS flag
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-184892@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=66641&edit=1

 ID:                 66641
 Updated by:         nikic@php.net
 Reported by:        corentin dot larose at qapa dot com
 Summary:            ArrayObject doens't call offsetSet when using +=
                     with ARRAY_AS_PROPS flag
-Status:             Open
+Status:             Not a bug
 Type:               Bug
 Package:            SPL related
 Operating System:   UBUNTU 12.04
 PHP Version:        5.4.24
 Block user comment: N
 Private report:     N

 New Comment:

This is an indirect modification of a property and as such goes through &offsetGet() rather than
offsetSet().


Previous Comments:
------------------------------------------------------------------------
[2014-02-04 14:16:47] 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
    )
)


------------------------------------------------------------------------



-- 
Edit this bug report at https://bugs.php.net/bug.php?id=66641&edit=1


Thread (3 messages)

« previous php.bugs (#184892) next »