对象对象中的自动函数?

考虑这个课程:
class Test {  
    public $obj;  

function __construct ($obj) {  
    $this->obj = $obj;  
}  
$ obj有自己的公共功能。我通过我的代码称它为
$t = new Test($obj); $t->obj->do();
我想允许$ obj为空,而不会触发错误。是否可以使用PHP的魔术函数执行一些技巧,如果未明确设置该函数,则始终返回false?此外,是否有PHP的解决方案< 5.3?     
已邀请:
我现在无法测试,但这可行:
class default {
      public function __call($name, $arguments) {
             return false;
      }
}

class Test {
      public $obj;
      public function __construct($obj = NULL) {
           if($obj === NULL) $this->obj = new default;
           else $this->obj = $obj
      }
}
    

要回复问题请先登录注册