Open In App

PHP | ReflectionFunction invoke() Function

Last Updated : 13 Dec, 2019
Improve
Improve
Like Article
Like
Save
Share
Report

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('GeeksforGeeks',
            'is a Computer Science Portal.');
  
// Getting the result of the invoked function company
echo $A;
?>


Output:

GeeksforGeeks 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



Similar Reads

PHP ReflectionFunction export() Function
The ReflectionFunction::export() function is an inbuilt function in PHP which is used to return the export as a string if the return parameter is set to TRUE, otherwise NULL is returned. Syntax: string ReflectionFunction::export( string $name, string $return ) Parameters: This function accepts two parameters as mentioned above and described below:
2 min read
PHP | ReflectionFunction invokeArgs() Function
The ReflectionFunction::invokeArgs() function is an inbuilt function in PHP which is used to return the result of the invoked function call. Syntax: mixed ReflectionFunction::invokeArgs( array $args ) Parameters: This function accepts a single parameter $args which holds the array of arguments passed to the called function. Return Value: This funct
2 min read
PHP | ReflectionFunction __toString() Function
The ReflectionFunction::__toString() function is an inbuilt function in PHP which is used to return the string representation of the specified function.Syntax: string ReflectionFunction::__toString( void ) Parameters: This function does not accept any parameters.Return Value: This function returns the string representation of the specified function
2 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 illustrated below: object: This is the initialized class ob
2 min read
How to invoke a function without parenthesis using JavaScript ?
Method 1: Using the new operator. The new operator is used to create an instance of an object which has a constructor function. This constructor function can be used to write our own function and then be invoked by the new operator. The parenthesis is optional when using this operator, hence the function would be invoked even without them. Syntax:
2 min read
Lodash _.invoke() Method
Lodash is a JavaScript library that works on the top of underscore.js. Lodash helps in working with arrays, collection, strings, lang, function, objects, numbers etc. The _.invoke() method is invoked the method at path of object. Syntax: _.invoke(object, path, args) Parameters: This method accepts three parameters as mentioned above and described b
2 min read
Fabric.js invoke() Method
The Fabric.js invoke() method is used to perform certain actions like sorting, joining, etc. on the elements of the specified array. Syntax: invoke(array, method) Parameters: This method accepts two parameters as mentioned above and described below: array: This parameter holds the array to iterate over.method: This parameter holds the name of a met
1 min read
Ember.js MutableArray invoke() Method
Ember.js is an open-source JavaScript framework used for developing large client-side web applications which is based on Model-View-Controller (MVC) architecture. Ember.js is one of the most widely used front-end application frameworks. It is made to speed up development and increase productivity. Currently, it is utilized by a large number of webs
3 min read
Ember.js EmberArray invoke() Method
Ember.js is an open-source JavaScript framework used for developing large client-side web applications which are based on Model-View-Controller (MVC) architecture. Ember.js is one of the most widely used front-end application frameworks. It is made to speed up development and increase productivity. Currently, it is utilized by a large number of web
3 min read
Ember.js ArrayProxy invoke() Method
Ember.js is an open-source JavaScript framework used for developing large client-side web applications which are based on Model-View-Controller (MVC) architecture. Ember.js is one of the most widely used front-end application frameworks. It is made to speed up development and increase productivity. Currently, it is utilized by a large number of web
4 min read