Php 使用参数调用静态函数,该函数没有成功执行的参数
大家好,我正在使用Php 使用参数调用静态函数,该函数没有成功执行的参数,php,function,static,static-methods,Php,Function,Static,Static Methods,大家好,我正在使用forward\u static\u call\u array()函数,我得到了一个示例 <?php class A { const NAME = 'A'; public static function test() { $args = func_get_args(); echo static::NAME, " ".join(',', $args)."<br/>"; } } class B exten
forward\u static\u call\u array()
函数,我得到了一个示例
<?php
class A
{
const NAME = 'A';
public static function test() {
$args = func_get_args();
echo static::NAME, " ".join(',', $args)."<br/>";
}
}
class B extends A
{
const NAME = 'B';
public static function test() {
echo self::NAME, "<br/>";
forward_static_call_array(array('A', 'test'), array('more', 'args'));
forward_static_call_array( 'test', array('other', 'args'));
}
}
B::test("bar");
function test() {
$args = func_get_args();
echo "C ".join(',', $args)."<br/>";
}
?>
但是当我查看代码时,我看到它正在调用B::test(“bar”)代码>其他2个test()
函数具有func\u get\u args()
。但是B::test
也没有。所以我认为它应该弹出一个错误。但它工作得很好
怎么样
- 所以,当我们在函数中使用
forward\u static\u call\u array()
时,函数中不需要参数吗
或
- 没有参数的PHP静态函数可以用参数调用吗
请解释一下。非常感谢。使用转发\u静态\u呼叫\u数组
并不特别。每个函数或方法都有这种行为
PHP支持用户定义的可变长度参数列表
功能。这是使用。。。PHP5.6中的令牌和
稍后,使用func_num_args()、func_get_arg()和
PHP5.5及更早版本中的func_get_args()函数
但是这个函数是公共静态函数test(){echo self::NAME,“
”;forward_static_call_array(array('A','test')、array('more','args'));forward_static_call_array('test',array('other','args'));},它是类B的测试函数,它没有任何函数get_args?@kanishkapanamaldenia,没关系。没有登机语言。但是有些函数可以检查它。
B
B more,args
C other,args
function sum() {
$acc = 0;
foreach (func_get_args() as $n) {
$acc += $n;
}
return $acc;
}
echo sum(1, 2, 3, 4);