Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
是否可以处理此类错误?类似 spl_autoload_register 的东西,但用于函数。
基本上,我想做的是:
我有课:
class Foo { public function bar() { echo 1; } }
所以,当我像这样调用一个不存在的函数 Foo() 时:
Foo()->bar();
可能的处理程序应该创建一个函数 Foo(),如下所示:
function Foo() { return new Foo(); }
如果您从不需要对象的实际实例,为什么不使用静态类呢?
class Foo { public static function bar() { echo 1; } } Foo::bar();
然后,您可以在您的应用程序中执行此操作:
$this->fiends = FriendsModel::getUserFriends($userId);