|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #32134 Overloading offsetGet/offsetSet
Submitted: 2005-02-28 17:09 UTC Modified: 2005-03-03 11:51 UTC
From: justinh at superglobals dot com Assigned: helly (profile)
Status: Closed Package: SPL related
PHP Version: 5.0.3 OS: *
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
38 + 29 = ?
Subscribe to this entry?

 [2005-02-28 17:09 UTC] justinh at superglobals dot com
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:
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
offsetSet called
offsetGet called

Actual result:
offsetSet called
offsetGet called


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2005-03-03 11:51 UTC]
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
Thank you for the report, and for helping us make PHP better.

PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Mon Dec 11 00:01:26 2023 UTC