01-Sep-2004 02:39
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);
?>