|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2004-09-06 18:51 UTC] orlum at mail dot ru
Description:
------------
When __get method accesses other property in some class, expected call to __get method not occurs, undefined property notice appears and null value of property returns.
Reproduce code:
---------------
<?PHP
class A
{
public function __get($property)
{
echo "__get()\n";
if ($property == "B")
return 1;
elseif ($property == "C")
return $this->B;
}
}
error_reporting(E_ALL);
$a = new A();
echo "B={$a->B}\n";
echo "C={$a->C}\n";
?>
Expected result:
----------------
__get()
B=1
__get()
__get()
C=1
Actual result:
--------------
__get()
B=1
__get()
Notice: Undefined property: A::$B in PHPDocument1 on line 12
C=
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Dec 03 11:00:01 2025 UTC |
Another exaple, where IMHO it should work: <?php class Creator { public $objects; public function __get($name) { if (!isset($this->objects[$name])) { $this->objects[$name] = new $name($this); } return $this->objects[$name]; } } class Class1 { public function __construct($Creat) { echo 'Class1'; $Creat->Class2; } } class Class2 { public function __construct($Creat) { echo 'Class2'; } } $Creat = new Creator; $Creat->Class1; ?> OUTPUT: Class1 Notice: Undefined property: Creator::$Class2 in D:\Server\www\noname\test.php on line 17 Expected: Class1Class2