Overloading Limitation- Can Someone Confirm?
| From: | Chris | Date: | Thu, 30 Mar 2006 12:07:15 +0000 |
| Subject: | Overloading Limitation- Can Someone Confirm? | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-232914@lists.php.net to get a copy of this message | ||
While playing with an unnamed framework, I think I discovered an overloading limitation (PHP 5.1.2). Can someone please confirm this limitation?
Example class:
class testClass
{
public $vars = array();
public function __get($key)
{
return array_key_exists($key, $this->vars) ? $this->vars[$key] : null;
}
public function __set($key, $value)
{
$this->vars[$key] = $value;
}
public function __isset($key)
{
return array_key_exists($key, $this->vars);
}
public function __unset($key)
{
unset($this->vars[$key]);
}
}
Given the above class, the following code will not work:
$tc = new testClass();
$tc->arr = array();
$tc->arr['a'] = 'A';
$tc->arr['b'] = 'B';
if (isset($tc->arr['b'])) {
unset($tc->arr['b']);} //var_dump is only to see results of above var_dump($tc); Am I a moron or, in fact, does this not work and is a language limitation? Chris chris@dented-planet.net