#32134 [Opn->Ver]: Overloading offsetGet/offsetSet

From: Date: Mon, 28 Feb 2005 19:02:17 +0000
Subject: #32134 [Opn->Ver]: Overloading offsetGet/offsetSet
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-76897@lists.php.net to get a copy of this message
 ID:               32134
 Updated by:       sniper@php.net
 Reported By:      justinh at superglobals dot com
-Status:           Open
+Status:           Verified
 Bug Type:         SPL related
-Operating System: FreeBSD 5.3-RELEASE
+Operating System: *
-PHP Version:      5.0.3
+PHP Version:      5CVS-2005-02-28


Previous Comments:
------------------------------------------------------------------------

[2005-02-28 17:09:53] justinh at superglobals dot com

Description:
------------
When extending the SPL ArrayIterator class and overloading the
offsetGet/offsetSet methods, it appears that neither of the overloaded
methods are called when accessing the object like an array (ie
$myObject['index'])

Reproduce code:
---------------
<?php
class myArray extends ArrayIterator
{

    public function __construct ($array = array ())
    {
        parent::__construct ($array);
    }

    public function offsetGet ($index)
    {
        echo 'offsetGet called';
        return parent::offsetGet ($index);
    }

    public function offsetSet ($index, $newval)
    {
        echo 'offsetSet called';
        return parent::offsetSet ($index, $newval);
    }

}

$myArray = new myArray ();

$myArray->offsetSet ('one', 'one');
echo $myArray->offsetGet ('one');

$myArray['two'] = 'two';
echo $myArray['two'];
?>

Expected result:
----------------
offsetSet called
offsetGet called
one
offsetSet called
offsetGet called
two

Actual result:
--------------
offsetSet called
offsetGet called
one
two


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=32134&edit=1


Thread (3 messages)

« previous php.bugs (#76897) next »