__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:
<?php
class
A{
public function __invoke($var){var_dump(
$var); echo"<br/>";}
}
$obj
=new A;$obj
(4);$obj
("Hello");$obj
(4.5);echo
"<b>is_callable() method is used to check whether an object can be called or not </b><br/>";var_dump(is_callable(
$obj));?>
Output:
int(4)If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.