#38118 [Opn->Bgs]: unrelated error when using reference
| From: | helly@php.net | Date: | Sun, 16 Jul 2006 23:55:44 +0000 |
| Subject: | #38118 [Opn->Bgs]: unrelated error when using reference | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-99485@lists.php.net to get a copy of this message | ||
ID: 38118
Updated by: helly@php.net
Reported By: public at grik dot net
-Status: Open
+Status: Bogus
-Bug Type: SPL related
+Bug Type: Scripting Engine problem
Operating System: *
PHP Version: 5.1.4
New Comment:
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
The '&' is because of inhereitance rules.
The second thing you encounter, the '&=' is an engine limitation.
Btw, both are pure engine issues, nothing todo with SPL.
Maybe you want this reopened as feature request. But then i suggest you
provide at least some ideas where and how to document that ArayAccess
cannot be used in modifying operators like '&='.
Either way you should try 5.2/HEAD first as we've put some work to get
you a better error message.
Previous Comments:
------------------------------------------------------------------------
[2006-07-16 23:43:09] public at grik dot net
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.
------------------------------------------------------------------------
[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