note 45269 deleted from language.oop5.overloading by danielc

From: Date: Thu, 03 Jul 2008 00:31:37 +0000
Subject: note 45269 deleted from language.oop5.overloading by danielc
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-141091@lists.php.net to get a copy of this message
Note Submitter: Reason: 2 ---- For those using isset(): Currently (php5.0.1) isset will not check the __get method to see if you can retrieve a value from that function. So if you want to check if an overloaded value is set you'd need to use something like the __isset method below: <?php class foo { public $aryvars = array(); function __construct() {} function __get($key) { return array_key_exists($key, $this->aryvars) ? $this->aryvars[$key] : null; } function __isset($key) { if (!$isset = isset($this->$key)) { $isset = array_key_exists($key, $this->aryvars); } return $isset; } function __set($key, $value) { $this->aryvars[$key] = $value; } } echo '<pre>'; $foo = new foo(); $foo->a = 'test'; echo '$foo->a == ' . $foo->a . "\n"; echo 'isset($foo->a) == ' . (int) isset($foo->a) . "\n"; echo 'isset($foo->aryvars[\'a\']) == ' . isset($foo->aryvars['a']) . "\n"; echo '$foo->__isset(\'a\') == ' . $foo->__isset('a') . "\n"; var_dump($foo); ?>

« previous php.notes (#141091) next »