note 114988 added to arrayobject.exchangearray
| From: | CorentinLarose | Date: | Fri, 09 May 2014 14:59:16 +0000 |
| Subject: | note 114988 added to arrayobject.exchangearray | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-199496@lists.php.net to get a copy of this message | ||
It's worth notting that ArrayObject::exchangeArray() doesn't call ArrayObject::offsetSet()
internally for each offset/property of the array/object provided in argument.
It's also worth noting the let's say "unexpected" behavior of get/set:
<?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_1'] ++;
++ $test['my_value_1'];
$test->my_value_2 = 1;
$test->my_value_2 = $test->my_value_2 + 1;
$test->my_value_2 += 1;
$test->my_value_2 ++;
++ $test->my_value_2;
print_r($test);
// Prints out:
MyArrayObject Object
(
[storage:ArrayObject:private] => Array
(
[my_value_1_control] => 3
[my_value_1] => 5
[my_value_2_control] => 2
[my_value_2] => 5
)
)
?>
----
Server IP: 72.52.91.14
Probable Submitter: 93.31.210.36
----
Manual Page -- http://php.net/manual/en/arrayobject.exchangearray.php
Edit -- https://master.php.net/note/edit/114988
Del: integrated -- https://master.php.net/note/delete/114988/integrated
Del: useless -- https://master.php.net/note/delete/114988/useless
Del: bad code -- https://master.php.net/note/delete/114988/bad+code
Del: spam -- https://master.php.net/note/delete/114988/spam
Del: non-english -- https://master.php.net/note/delete/114988/non-english
Del: in docs -- https://master.php.net/note/delete/114988/in+docs
Del: other reasons-- https://master.php.net/note/delete/114988
Reject -- https://master.php.net/note/reject/114988
Search -- https://master.php.net/manage/user-notes.php