php.net |  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
 [2003-07-24 05:20 UTC] proton at fangen dot net
Description:
------------
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
NULL 
Notice: Undefined offset: 2 in myfile.php on line 26
NULL 

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-07-24 08:15 UTC] zeev@php.net
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 http://snaps.php.net/.
 
In case this was a documentation problem, the fix will show up soon at
http://www.php.net/manual/.

In case this was a PHP.net website problem, the change will show
up on the PHP.net 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: Sat Apr 20 14:01:29 2024 UTC