June 2017
Intermediate to advanced
536 pages
9h 49m
English
The __invoke() magic method gets triggered when the object is being called as a function. The method accepts an optional number of parameters and is is able to return various types of data, or no data at all, as per the following synopsis:
mixed __invoke([ $... ])
If an object class implements the __invoke() method, we can call the method by specifying parentheses () right after the object's name. This type of object is known as a functor or function object.
The following block of code illustrates the simple __invoke() implementation:
<?phpclass User{ public function __invoke($name, $age) { echo $name . ', ' . $age; }Read now
Unlock full access