note 45269 added to language.oop5.overloading
| From: | php-general at lists dot php dot net | Date: | Tue, 31 Aug 2004 18:39:03 +0000 |
| Subject: | note 45269 added to language.oop5.overloading | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-75764@lists.php.net to get a copy of this message | ||
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);
?>
----
Manual Page -- http://www.php.net/manual/en/language.oop5.overloading.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+45269
Delete -- http://master.php.net/manage/user-notes.php?action=delete+45269&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+45269&report=yes
Search -- http://master.php.net/manage/user-notes.php