让我们假设你有一个单例模式或什么:忽略不存在的方法
class Smth{
public static function Foo(){
static $instance;
if(!condition()) return false; // <-- it's nothing...
if(!($instance instanceof FooClass)) $instance = new FooClass();
return $instance; // <-- it's a object and has that method
}
}
所以如果我叫Smth::foo()->A_foo_method()
时condition()
满足,则执行该法,一切都OK。
但如果condition()
不符合,很明显,我得到一个致命的错误,告诉我,Smth::foo()
不是一个对象等等......
我怎么能简单地忽略第二个情况?我的意思是不要做任何事情,也不要显示致命的错误。
(除了检查条件()类外,在调用方法时)
我假设你想把'$ instance'作为对'Foo'的引用?你还可以详细说明'condition()' – 2011-06-06 15:09:13
'condition()'是一个正常的函数,用于检查当前正在显示的页面是否为特定的页面... – Alex 2011-06-06 15:10:08