|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2006-08-29 11:08 UTC] tony2001@php.net
[2006-11-29 22:12 UTC] tony2001@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Dec 03 03:00:01 2025 UTC |
Description: ------------ When unsetting object property it unsetted from object then __get method of object is called while accessing it. Besides property exists in all reflection objects (ReflectionObject and ReflectionProperty) but cause Fatal error while getting it. Reproduce code: --------------- <?php class B{} class A { public $Var = null; public function __construct() { $this->Var= new B(); } public function __get($name) { echo "get {$name}\n"; if(isset($this->Var)) { return $this->Var; } else { echo "Undefined variable\n"; return null; } } public function __unset($nm) { echo "unset"; } } $a = new A(); unset($a->Var); $o = new ReflectionObject($a); $p = $o->getProperty('Var'); Reflection::export($o);//Variable Exists Reflection::export($p);//Variable Exists var_dump($a->Var);//__get called var_dump($p->getValue($a)); //Fatal error ?> Expected result: ---------------- $o = new ReflectionObject($a); has correct current instance properties or $p->getValue($a) - will call __get method too and not cause fatal error. Actual result: -------------- Object of class [ <user> class A ] { @@ D:\WWW\www.usoftinc.com\test2.php 3-27 - Constants [0] { } - Static properties [0] { } - Static methods [0] { } - Properties [1] { Property [ <default> public $Var ] } - Dynamic properties [0] { } - Methods [3] { Method [ <user, ctor> public method __construct ] { @@ D:\WWW\www.usoftinc.com\test2.php 6 - 9 } Method [ <user> public method __get ] { @@ D:\WWW\www.usoftinc.com\test2.php 10 - 22 - Parameters [1] { Parameter #0 [ <required> $name ] } } Method [ <user> public method __unset ] { @@ D:\WWW\www.usoftinc.com\test2.php 23 - 26 - Parameters [1] { Parameter #0 [ <required> $nm ] } } } } Property [ <default> public $Var ] get Var Undefined variable NULL <br /> <b>Fatal error</b>: Internal error: Could not find the property Var in <b>test2.php</b> on line <b>36</b><br />