PHP | ReflectionMethod invokeArgs() Function
The ReflectionMethod::invokeArgs() function is an inbuilt function in PHP which is used to invoke the specified reflected method and returns the result of the method.
Syntax:
mixed ReflectionMethod::invokeArgs ( $object, $parameter )
Parameters: This function accepts two parameters as mentioned above and described below:
- object: This is the initialized class object.
- parameter: This is the array of zero or more parameters to be passed to the method.
Return Value: This function returns the result of the invoked method.
Below programs illustrate the ReflectionMethod::invokeArgs() function in PHP:
Program 1:
php
<?php
class Company {
public function GFG( $name ) {
return 'GeeksforGeeks' . $name ;
}
}
$A = new ReflectionMethod( 'Company' , 'GFG' );
$B = $A ->invokeArgs( new Company(),
array ( ' is a Computer Science Portal.' ));
echo $B ;
?>
|
Output:
GeeksforGeeks is a Computer Science Portal.
Program 2:
php
<?php
class Department1 {
public function hr( $name ) {
return 'HR' . $name ;
}
}
class Department2 {
public function coding( $name ) {
return 'Coding' . $name ;
}
}
class Department3 {
public function marketing( $name ) {
return 'Marketing' . $name ;
}
}
$A = new ReflectionMethod( 'Department1' , 'hR' );
$B = new ReflectionMethod( 'Department2' , 'coding' );
$C = new ReflectionMethod( 'Department3' , 'marketing' );
echo $A ->invokeArgs( new Department1(),
array ( ' is a Department.' ));
echo "\n" ;
echo $B ->invokeArgs( new Department2(),
array ( ' is also a Department.' ));
echo "\n" ;
echo $C ->invokeArgs( new Department3(),
array ( ' too.' ));
?>
|
Output:
HR is a Department.
Coding is also a Department.
Marketing too.
Reference: https://www.php.net/manual/en/reflectionmethod.invokeargs.php
Last Updated :
08 Jul, 2021
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...