From:             public at grik dot net
Operating system: *
PHP version:      5.1.4
PHP Bug Type:     SPL related
Bug description:  unrelated error when using reference

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 bug report at http://bugs.php.net/?id=38118&edit=1
-- 
Try a CVS snapshot (PHP 4.4): 
http://bugs.php.net/fix.php?id=38118&r=trysnapshot44
Try a CVS snapshot (PHP 5.2): 
http://bugs.php.net/fix.php?id=38118&r=trysnapshot52
Try a CVS snapshot (PHP 6.0): 
http://bugs.php.net/fix.php?id=38118&r=trysnapshot60
Fixed in CVS:                 http://bugs.php.net/fix.php?id=38118&r=fixedcvs
Fixed in release:             
http://bugs.php.net/fix.php?id=38118&r=alreadyfixed
Need backtrace:               http://bugs.php.net/fix.php?id=38118&r=needtrace
Need Reproduce Script:        http://bugs.php.net/fix.php?id=38118&r=needscript
Try newer version:            http://bugs.php.net/fix.php?id=38118&r=oldversion
Not developer issue:          http://bugs.php.net/fix.php?id=38118&r=support
Expected behavior:            http://bugs.php.net/fix.php?id=38118&r=notwrong
Not enough info:              
http://bugs.php.net/fix.php?id=38118&r=notenoughinfo
Submitted twice:              
http://bugs.php.net/fix.php?id=38118&r=submittedtwice
register_globals:             http://bugs.php.net/fix.php?id=38118&r=globals
PHP 3 support discontinued:   http://bugs.php.net/fix.php?id=38118&r=php3
Daylight Savings:             http://bugs.php.net/fix.php?id=38118&r=dst
IIS Stability:                http://bugs.php.net/fix.php?id=38118&r=isapi
Install GNU Sed:              http://bugs.php.net/fix.php?id=38118&r=gnused
Floating point limitations:   http://bugs.php.net/fix.php?id=38118&r=float
No Zend Extensions:           http://bugs.php.net/fix.php?id=38118&r=nozend
MySQL Configuration Error:    http://bugs.php.net/fix.php?id=38118&r=mysqlcfg

Reply via email to