PHP :: Bug #32134 :: Overloading offsetGet/offsetSet
| 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 | ||
[2005-02-28 17:09 UTC] 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
Patches
Pull Requests
History
AllCommentsChangesGit/SVN commits
[2005-03-03 11:51 UTC] helly@php.net