|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2008-07-29 12:14 UTC] colder@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Nov 15 05:00:02 2025 UTC |
Description: ------------ When an element of ArrayObject is incremented (++ operation), the object does not call its offsetSet method. I've tried overloading all public methods in ArrayObject: offsetGet is called, but not offsetSet or any other. Same with decrementing (--). This behaviour makes it impossible to handle all array modifications by overloading ArrayObject methods in derived class. Reproduce code: --------------- class myArray extends ArrayIterator { public function offsetSet($index, $newval) { echo "offsetSet called\n"; return parent::offsetSet($index, $newval); } } $a = new myArray(array('x' => 1)); echo "x += 1\n"; $a['x'] += 1; // calls offsetGet, then offsetSet with updated value echo $a['x']."\n"; echo "x++\n"; $a['x']++; // only calls offsetGet echo $a['x']."\n"; // but the value gets incremented Expected result: ---------------- x += 1 offsetSet called 2 x++ offsetSet called 3 Actual result: -------------- x += 1 offsetSet called 2 x++ 3