开发者

Call to undefined function handler

开发者 https://www.devze.com 2023-02-05 11:59 出处:网络
Is it possible to handle this type of errors? Something like spl_autoload_register, but for functions.

Is it possible to handle this type of errors? Something like spl_autoload_register, but for functions.

Basically, what I am trying to do:

I have the class:

class Foo {
   public function bar() {
     echo 1;
   } 
}

So, when I call a nonexistent function开发者_开发技巧 Foo() like this:

Foo()->bar();

The possible handler should create a function Foo(), which looks like that:

function Foo() {
   return new Foo();
}


If you never need an actual instance of the object, why not use a static class?

class Foo {
   public static function bar() {
     echo 1;
   } 
}

Foo::bar();

Then, you can do this in your app:

$this->fiends = FriendsModel::getUserFriends($userId);
0

精彩评论

暂无评论...
验证码 换一张
取 消