Share on Google+Share on Google+

PHP invoke Method


Have you ever wondered that how to call an object as function? Thanks to __invoke method, introduced in PHP 5.3.0, with the help of this function we can do it. The present tutorial is all about this PHP invoke function.

__invoke() Function in PHP:

PHP 5.3.0 has introduced so many new concepts, new functions. __invoke() is one of them. The functionality of __invoke() method is quite different from others. It is new and elegant in this class. Have you ever heard that we can call an object as function? I suppose no, but with the help of __invoke() method it is possible and just because of it's magical property it is included in magic methods.

So, let's try to evaluate what is it actually and how it works? Hope the following example will exemplify:

PHP Invoke Method Example:


class A


public function __invoke($var){





$obj=new A;




echo "<b>is_callable() method is used to check whether an object can be called or not </b><br/>";





string(5) "Hello"
is_callable() method is used to check whether an object can be called or not


Posted on: March 4, 2010 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.


Advertisement null