|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #24790 Array access broken with class variables
Submitted: 2003-07-24 05:20 UTC Modified: 2003-07-24 08:15 UTC
From: proton at fangen dot net Assigned:
Status: Closed Package: Class/Object related
PHP Version: 5CVS-2003-07-24 (dev) OS: Windows XP Home
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:
33 - 21 = ?
Subscribe to this entry?

 [2003-07-24 05:20 UTC] proton at fangen dot net
Accessing $this->values['foo']['bar']['2'] does not work like expected inside a class while accessing $values['foo']['bar']['2'] does work like expected.. It's a little hard to explain so I'll just let the code speak for itself:

Reproduce code:
$values = array(
	'foo' => array(
		'bar' => array(
			'2' => 'whatever'

var_dump($values['foo']['bar']['2']); // This works as expected

class MyClass
	var $values = array(
		'foo' => array(
			'bar' => array(
				'2' => 'whatever'

	function __construct()
		var_dump($this->values['foo']['bar']['2']); // This doesn't...
		var_dump($this->values['foo']['bar'][2]); // This doesn't either...

$c = new MyClass;

Expected result:
string(8) "whatever"
string(8) "whatever" 
string(8) "whatever" 

Actual result:
string(8) "whatever" 
Notice: Undefined offset: 2 in myfile.php on line 25
Notice: Undefined offset: 2 in myfile.php on line 26


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2003-07-24 08:15 UTC]
This bug has been fixed in CVS.

In case this was a PHP problem, snapshots of the sources are packaged
every three hours; this change will be in the next snapshot. You can
grab the snapshot at
In case this was a documentation problem, the fix will show up soon at

In case this was a website problem, the change will show
up on the site and on the mirror sites in short time.
Thank you for the report, and for helping us make PHP better.

PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri May 24 07:01:35 2024 UTC