PHP | ReflectionMethod getClosure() Function Last Updated : 19 Aug, 2021 Comments Improve Suggest changes Like Article Like Report The ReflectionMethod::getClosure() function is an inbuilt function in PHP which is used to return a dynamically created closure for the method otherwise, return NULL in case of an error. Syntax: Closure ReflectionMethod::getClosure ( $object ) Parameters: This function accepts a parameter object which is the specified user-defined class object. Return Value: This function returns a dynamically created closure for the method otherwise, return NULL in case of an error. Below programs illustrate the ReflectionMethod::getClosure() function in PHP: Program_1: PHP <?php // Initializing a user-defined class class Company { protected function GeeksforGeeks($name) { return 'GFG' . $name; } } // Using ReflectionMethod() over the class Company $A = new ReflectionMethod('Company', 'GeeksforGeeks'); // Calling the getClosure() function $B = $A->getClosure(new Company()); // Getting a dynamically created closure // for the method otherwise, return NULL // in case of an error. var_dump($B); ?> Output: object(Closure)#3 (2) { ["this"]=> object(Company)#2 (0) { } ["parameter"]=> array(1) { ["$name"]=> string(10) "<required>" } } Program_2: PHP <?php // Initializing some user-defined classes class Department1 { protected function HR($name) { return 'hr' . $name; } } class Department2 { protected function Coding($name) { return 'coding' . $name; } } class Department3 { protected function Marketing($name) { return 'marketing' . $name; } } // Using ReflectionMethod() over the above classes $A = new ReflectionMethod('Department1', 'HR'); $B = new ReflectionMethod('Department2', 'Coding'); $C = new ReflectionMethod('Department3', 'Marketing'); // Calling the getClosure() function and // Getting a dynamically created closure // for the method otherwise, return NULL // in case of an error. var_dump($A->getClosure(new Department1())); var_dump($B->getClosure(new Department2())); var_dump($C->getClosure(new Department3())); ?> Output: object(Closure)#5 (2) { ["this"]=> object(Department1)#4 (0) { } ["parameter"]=> array(1) { ["$name"]=> string(10) "<required>" } } object(Closure)#4 (2) { ["this"]=> object(Department2)#5 (0) { } ["parameter"]=> array(1) { ["$name"]=> string(10) "<required>" } } object(Closure)#5 (2) { ["this"]=> object(Department3)#4 (0) { } ["parameter"]=> array(1) { ["$name"]=> string(10) "<required>" } } Reference: https://www.php.net/manual/en/reflectionmethod.getclosure.php Comment More infoAdvertise with us Next Article PHP | ReflectionMethod getClosure() Function K Kanchan_Ray Follow Improve Article Tags : Web Technologies PHP PHP-function PHP- Reflection Similar Reads PHP | ReflectionMethod getModifiers() Function The ReflectionMethod::getModifiers() function is an inbuilt function in PHP which is used to return the numeric representation of the method modifiers. Syntax: int ReflectionMethod::getModifiers( void ) Parameters: This function does not accept any parameter. Return Value: This function returns the 1 min read PHP | ReflectionMethod getPrototype() Function The ReflectionMethod::getPrototype() function is an inbuilt function in PHP which is used to return the prototype of the specified method otherwise, an exception/error is returned if the method does not have a prototype. Syntax: ReflectionMethod ReflectionMethod::getPrototype( void ) Parameters: Thi 2 min read PHP | ReflectionMethod isDestructor() Function The ReflectionMethod::isDestructor() function is an inbuilt function in PHP which is used to return TRUE if the specified method is destructor, otherwise FALSE. Syntax: bool ReflectionMethod::isDestructor( void ) Parameters: This function does not accept any parameters. Return Value: This function r 1 min read PHP | ReflectionMethod invoke() Function The ReflectionMethod::invoke() function is an inbuilt function in PHP which is used to invoke the specified reflected method and returns the result of the method.Syntax: public mixed ReflectionMethod::invoke ( $object, $parameter ) Parameters: This function accepts two parameters which are illustrat 2 min read PHP | ReflectionMethod isPrivate() Function The ReflectionMethod::isPrivate() function is an inbuilt function in PHP which is used to return TRUE if the specified method is private, otherwise returns FALSE. Syntax: bool ReflectionMethod::isPrivate( void ) Parameters: This function does not accept any parameters. Return Value: This function re 2 min read Like