Question

I was looking at the codebird-php git and noticed that the author has a way to detect methods that are not declared in the class itself. For example, he has

$cb->statuses_homeTimeline();

which successfully executes, despite there not being a method called statuses_homeTimeline() in the Codebird class.

I've tried looking for information regarding this type of construction, but without knowing what it's called, I haven't found anything.

What is it generally called (I've googled all variations of "variable methods," "mapping methods," etc)? Are there arguments against its use? How does it (in principle) work?

Était-ce utile?

La solution

I found a bunch of questions involving __call and things you can do with it, but nothing about what __call actually is.

PHP objects have a number of Magic Methods. The most well-known being __construct.

__call is a magic method which gets called whenever you try and call a method that doesn't exist. It's sort of a "catch-all" for methods.

The technical term is "Method Overloading".

So when $cb->statuses_homeTimeline() is called, if that method does not exist, it will instead call
$cb->__call("statuses_homeTimeline",array())

Autres conseils

__call() magic method. __call() is triggered when invoking inaccessible methods in an object context.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top