#32134 [NEW]: Overloading offsetGet/offsetSet

From: Date: Mon, 28 Feb 2005 16:09:53 +0000
Subject: #32134 [NEW]: Overloading offsetGet/offsetSet
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-74690@lists.php.net to get a copy of this message
From:             justinh at superglobals dot com
Operating system: FreeBSD 5.3-RELEASE
PHP version:      5.0.3
PHP Bug Type:     SPL related
Bug description:  Overloading offsetGet/offsetSet

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


Thread (3 messages)

« previous php.bugs (#74690) next »