Bug #66641 [Com]: ArrayObject doens't call offsetSet when using += with ARRAY_AS_PROPS flag
Edit report at https://bugs.php.net/bug.php?id=66641&edit=1
ID: 66641
Comment 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: 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:
I meant &__get() and __set() there, of course.
Previous Comments:
------------------------------------------------------------------------
[2014-03-26 11:05:42] nikic@php.net
This is an indirect modification of a property and as such goes through &offsetGet() rather than
offsetSet().
------------------------------------------------------------------------
[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)