#32983 [Com]: Bogus error message when using ArrayAccess / References

From: Date: Tue, 16 Aug 2005 05:44:51 +0000
Subject: #32983 [Com]: Bogus error message when using ArrayAccess / References
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-83625@lists.php.net to get a copy of this message
ID: 32983 Comment by: sslotnick at gmail dot com Reported By: jason at amp-design dot net Status: Assigned Bug Type: SPL related Operating System: * PHP Version: 5CVS-2005-06-19 Assigned To: helly New Comment: I have a similar but different reproduction using two dimensional arrays instead of explicitly setting a reference. class ArrayAccessImpl implements ArrayAccess { private $data = array(); public function offsetUnset($index) {} public function offsetSet($index, $value) { $this->data[$index] = $value; } public function offsetGet($index) { return $this->data[$index]; } public function offsetExists($index) { return isset($this->data[$index]); } } $data = new ArrayAccessImpl(); $data['element'] = array(); $data['element']['element2'] = "hi"; Previous Comments: ------------------------------------------------------------------------ [2005-05-09 19:05:42] helly@php.net Actually at the moment this is a known issue which we cannot fix appropriate right away. But we are working on the matter. ------------------------------------------------------------------------ [2005-05-09 12:38:42] jason at amp-design dot net Description: ------------ I'm not 100% sure this is considered a "bug" as such, anyway, I thought I'd point it out, and let you decide. It's more a case of the error message being a little fuzzy. When trying to assign an item by reference by using the reference operator, &, to an element inside a class that implements ArrayAccess produces a werid error message. Admittedly, the code I've provided is probably not valid PHP code, because the nature of the ArrayAccess interface means that data is assigned and returned from offsetSet and offsetGet by value, so using refernces should probably not work. However, the when you do try this, you get an error about about post/pre increment/decrement. I'm not sure what this refers to, but it doesn't seem to be very descriptive. Reproduce code: --------------- <?php class ArrayAccessImpl implements ArrayAccess { private $data = array(); public function offsetUnset($index) {} public function offsetSet($index, $value) { $this->data[$index] = $value; } public function offsetGet($index) { return $this->data[$index]; } public function offsetExists($index) { return isset($this->data[$index]); } } $data = new ArrayAccessImpl(); $test = 'some data'; $data['element'] = &$test; ?> Expected result: ---------------- Unsure, probably an error message relating to the fact ArrayAccess objects can not assign by reference Actual result: -------------- Fatal error: Objects used as arrays in post/pre increment/decrement must return values by reference ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=32983&edit=1

« previous php.bugs (#83625) next »