php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #29458 Dereferencing, __get and array property
Submitted: 2004-07-30 16:03 UTC Modified: 2005-02-15 00:29 UTC
Votes:5
Avg. Score:4.8 ± 0.4
Reproduced:4 of 4 (100.0%)
Same Version:3 (75.0%)
Same OS:4 (100.0%)
From: hawcue at yahoo dot com Assigned:
Status: Closed Package: Class/Object related
PHP Version: 5.0.0 OS: Windows XP
Private report: No CVE-ID: None
 [2004-07-30 16:03 UTC] hawcue at yahoo dot com
Description:
------------
Part of this report is related with BUG#24807.

In the following code, I would like to get and set an object property in the way similar to that in Java, C# and Delphi, e.g., "$a->Child->Name='xxx'" and "echo $a->Child->Name". However, the PHP parser would not allow the first usage.

Another question is about array property. Within current PHP5 release, I can't see a way to define an object property that is of array type and supports access to individual array element.

These two questions may not be considered as bugs, however, to my belief they are very fundamental to object properties.

Reproduce code:
---------------
class Input {
	private $_name='abc';
	private $_child;
	function __get($name) {
		if($name=='Name')
			return $this->_name;
		else if($name=='Child') {
			if(!isset($this->_child))
				$this->_child=new Input;
			return $this->_child;
		}
	}
	function __set($name,$value) {
		if($name=='Name')
			$this->_name=$value;
	}
}
$a=new Input;
$a->Child->Name='cde';
echo $a->Child->Name;

Expected result:
----------------
cde

Actual result:
--------------
Fatal error: Cannot access undefined property for object with overloaded property access ...

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-02-15 00:29 UTC] tony2001@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.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Dec 26 14:01:30 2024 UTC