php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #33799 Inheriting of ArrayObject causes a strange behaviour
Submitted: 2005-07-21 09:34 UTC Modified: 2005-07-22 13:26 UTC
From: stochnagara at hotmail dot com Assigned:
Status: Closed Package: Class/Object related
PHP Version: 5.0.* OS: *
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: stochnagara at hotmail dot com
New email:
PHP Version: OS:

 

 [2005-07-21 09:34 UTC] stochnagara at hotmail dot com
Description:
------------
When I extend the ArrayObject class, I cannot override any of the functions offsetXXX. Also when using var_dump i see only "Array" element and I don't see my new public property $name.

I suppose the second thing is a bug. But the first one is maybe a feature that one cannot override internal PHP functions.

Reproduce code:
---------------
<?
class AO2 extends ArrayObject {
	public $name;
	public function offsetGet ($index) {
		echo "Calling offsetGet for index $index\n";
		return parent::offsetGet ($index);
	}
}

$a = new AO2();
$a->name = "123";
$a[5] = 'Hi';
echo "a[5] = {$a[5]}\n";;
echo "a->name = {$a->name}\n";;
var_dump($a);
?>

Expected result:
----------------
Calling offsetGet for index 5
a[5] = Hi
a->name = 123
object(AO2)#1 (1) {
  [5]=>
  string(2) "Hi"
  ["name"]=>
  string(3) "123"
}


Actual result:
--------------
a[5] = Hi
a->name = 123
object(AO2)#1 (1) {
  [5]=>
  string(2) "Hi"
}

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-07-21 10:23 UTC] tony2001@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php


 [2005-07-21 11:51 UTC] helly@php.net
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
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.

As tony answered double check the documentation for your var_dump problem and then look into ext/spl/tests for the array tests that make use of ArrayObject flags. Furthermore what you want only works with 5.1.
 [2005-07-22 13:26 UTC] stochnagara at hotmail dot com
Thanks for the fix. You are really fast:)

Now my offsetGet is called.

And about setFlags - I see that it is not documented yet, so I cannot see any information about it in the documentation. I see also that setFlags has only two values. 0 shows array elements and 1 shows other properties. Maybe there should be an option to show both of them. 

Thanks again!
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Jan 15 10:01:29 2025 UTC