Overwriting offset methods of ArrayObject
| From: | Klaus Reimer | Date: | Sun, 14 Nov 2004 16:11:03 +0000 |
| Subject: | Overwriting offset methods of ArrayObject | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-201975@lists.php.net to get a copy of this message | ||
Hello,
I just tried to overwrite a method of ArrayObject like this:
class MyArrayObject extends ArrayObject
{
public function offsetGet($key)
{
echo "Here I am\n";
return parent::offsetGet($key);
}
}
$o = new MyArrayObject();
$o['test'] = 'test';
echo $o['test'];
I think this should output the text "Here I am" because I have overwritten the offsetGet method of ArrayObject which is called if I access an array element of this object. But it doesn't. My method is simply ignored.
Then I've written a simple Object which implements the ArrayAccess interface like the ArrayObject object does. And then I have done the same as above but this time I don't extend ArrayObject but my own object. This works. My overwrite method is called
I'm confused. Why can't I overwrite the method in ArrayObject? Is this a bug? Or are the methods of ArrayObject marked as "final"? But even then I must get an "Cannot override final method" error.
Some hints if I misunderstood something? If not I'm going to file a bug report.