![]() |
PHP 7 Closure::call() method can bind an object scope, along with calling the closure temporarily. It takes the argument as an object and a variable number of parameters to be bound. Syntax: public Closure::call(object $newThis, mixed ...$args): mixed Parameters: It takes two parameters, which are described below:
Return Value: The return value for the Closure will be returned by this function. Example 1: This code snippet declares a class “Person” with a constructor that takes two arguments $name and $age. It then creates an instance of the “Person” class and assigns it to the variable $person. Finally, it prints the person’s name and age using the getName() and getAge() methods of the $person object. PHP
Output: Name: Geek Age: 23 Example 2:The code defines a “Geekcalculator” class with an add() method that creates a closure to call the add() method of the current object. It then uses the Closure::call() method to call the closure with the current object and the given arguments. The result is returned and printed on the screen. PHP
Output: 100 Reference: https://www.php.net/manual/en/closure.call.php |
Reffered: https://www.geeksforgeeks.org
PHP |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 15 |