ID: 38118 User updated by: public at grik dot net Reported By: public at grik dot net Status: Open Bug Type: SPL related Operating System: * PHP Version: 5.1.4 New Comment:
P.S. I am not allowed to define function offsetGet($key)as "function &offsetGet($key){...}" to return the value by reference due to the requirements of the ArrayAccess interface. Previous Comments: ------------------------------------------------------------------------ [2006-07-16 23:37:34] public at grik dot net Description: ------------ Slightly modifying a Harry Fuecks's sample from sitepoint.com on implemening the ArrayAccess interface, I get some unrelated error. Maybe it's a documentation bug again... Reproduce code: --------------- <?php class Article implements ArrayAccess { public $title; function __construct($title) { $this->title = $title; } function offsetSet($key, $value){ $this->{$key} = &$value; } function offsetGet($key){ return $this->{$key}; } function offsetUnset($key){ unset($this->{$key}); } function offsetExists($offset) { return array_key_exists($offset,get_object_vars($this)); } } // Create the object $A = new Article('SPL Rocks'); // Change the title using array syntax using reference $str = 'SPL _really_ rocks'; $A['title'] =&$str; // Check what it looks like again print_r($A); ?> Expected result: ---------------- Article Object ( [title] => SPL _really_ rocks ) Actual result: -------------- Fatal error: Objects used as arrays in post/pre increment/decrement must return values by reference in test.php on line 27 There was no increment/decrement operations used. It would be _much_ better if it would be allowed to write function offsetSet($key, &$value){...} ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=38118&edit=1