超越PHP PHP动态 | 经典文章 | CLASS | 相关下载 | 常见问题 | FORUM | WIKI | 在线手册
Site search:    
<Object InterfacesObject Iteration>
Last updated: Fri, 22 Jun 2007



add a note add a note User Contributed Notes
Overloading
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);

?>

<Object InterfacesObject Iteration>
 Last updated: Fri, 22 Jun 2007
view source | feedback | send page | sitemap | aboutus   
Copyright ® 2002-2003 PHPE.NET. All rights reserved
Last updated:2002-11-22