📜  PHP | ReflectionMethod invokeArgs()函数

📅  最后修改于: 2022-05-13 01:56:54.491000             🧑  作者: Mango

PHP | ReflectionMethod invokeArgs()函数

ReflectionMethod::invokeArgs()函数是PHP中的一个内置函数,用于调用指定的反射方法并返回该方法的结果。
句法:

mixed ReflectionMethod::invokeArgs ( $object, $parameter )

参数:该函数接受上面提到的两个参数,如下所述:

  • object:这是初始化的类对象。
  • 参数:这是要传递给方法的零个或多个参数的数组。

返回值:此函数返回调用方法的结果。
下面的程序说明了PHP中的ReflectionMethod::invokeArgs()函数
方案一:

php
invokeArgs(new Company(),
      array(' is a Computer Science Portal.'));
 
// Getting the result of the invoked method.
echo $B;
?>


php
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.'));
?>


输出:
GeeksforGeeks is a Computer Science Portal.

方案二:

PHP

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.'));
?>
输出:
HR is a Department.
Coding is also a Department.
Marketing too.

参考: https://www. PHP.net/manual/en/reflectionmethod.invokeargs。 PHP