PHP | ReflectionMethod invoke()函数
ReflectionMethod::invoke()函数是PHP中的一个内置函数,用于调用指定的反射方法并返回该方法的结果。
句法:
public mixed ReflectionMethod::invoke ( $object, $parameter )
参数:此函数接受两个参数,如下所示:
- object:这是初始化的类对象。
- 参数:这是要传递给方法的零个或多个参数。
返回值:此函数返回调用方法的结果。
下面的程序说明了PHP中的ReflectionMethod::invoke()函数:
程序_1:
php
invoke(new Company(),
' is a Computer Science Portal.');
// Getting the result of the invoked method.
echo $B;
?>
php
invoke(new Department1(), ' is a Department.');
echo "\n";
echo $B->invoke(new Department2(), ' is also a Department.');
echo "\n";
echo $C->invoke(new Department3(), ' too.');
?>
输出:
GeeksforGeeks is a Computer Science Portal.
程序_2:
PHP
invoke(new Department1(), ' is a Department.');
echo "\n";
echo $B->invoke(new Department2(), ' is also a Department.');
echo "\n";
echo $C->invoke(new Department3(), ' too.');
?>
输出:
HR is a Department.
Coding is also a Department.
Marketing too.
参考: https://www. PHP.net/manual/en/reflectionmethod.invoke。 PHP,