Friday, October 17, 2025
HomeLanguagesPHP | ReflectionFunction invoke() Function

PHP | ReflectionFunction invoke() Function

The ReflectionFunction::invoke() function is an inbuilt function in PHP which is used to return the result of the invoked function call.

Syntax:

mixed ReflectionFunction::invoke( mixed $args)

Parameters: This function accept parameter $args which holds the list of arguments passed to the called function.

Return Value: This function returns the result of the invoked function call.

Below programs illustrate the ReflectionFunction::invoke() function in PHP:

Program_1:




<?php
  
// Initializing a user-defined function
function Company($Company_Name, $Role) {
    return sprintf("%s %s\r\n", $Company_Name, $Role);
}
  
// Using ReflectionFunction() over the
// specified function company
$function = new ReflectionFunction('company');
  
// Calling the invoke() function
$A = $function->invoke('neveropen',
            'is a Computer Science Portal.');
  
// Getting the result of the invoked function company
echo $A;
?>


Output:

neveropen is a Computer Science Portal.

Program_2:




<?php
  
// Initializing some user-defined functions
function Trial1($First_Args, $Second_Args) {
    return sprintf("%s %s\r\n", $First_Args, $Second_Args);
}
  
function Trial2($First_Args, $Second_Args) {
    return sprintf("%s %s\r\n", $First_Args, $Second_Args);
}
  
// Using ReflectionFunction() over the above
// specified functions 
$function = new ReflectionFunction('Trial1');
$function = new ReflectionFunction('Trial2');
  
// Calling the invoke() function and getting the
// result of the invoked function company
echo $function->invoke('a+a', '= 2a');
echo $function->invoke('a*a', '= a^2');
?>


Output:

a+a = 2a
a*a = a^2

Reference: https://www.php.net/manual/en/reflectionfunction.invoke.php

RELATED ARTICLES

Most Popular

Dominic
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11954 POSTS0 COMMENTS
Shaida Kate Naidoo
6852 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS