Question

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();
}
Was it helpful?

Solution

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);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top