array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'zh', ), 'this' => array ( 0 => 'function.forward-static-call.php', 1 => 'forward_static_call', ), 'up' => array ( 0 => 'ref.funchand.php', 1 => '函数处理 函数', ), 'prev' => array ( 0 => 'function.forward-static-call-array.php', 1 => 'forward_static_call_array', ), 'next' => array ( 0 => 'function.func-get-arg.php', 1 => 'func_get_arg', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'zh', 'path' => 'reference/funchand/functions/forward-static-call.xml', ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); ?>
(PHP 5 >= 5.3.0, PHP 7, PHP 8)
forward_static_call — 调用静态方法
使用以下参数,调用通过 callback
参数给出的用户定义的函数或者方法。此函数必须在方法上下文中调用,不能在类外调用。它使用后期静态绑定
返回函数结果,失败时返回 false
。
示例 #1 forward_static_call() 示例
<?php
class A
{
const NAME = 'A';
public static function test() {
$args = func_get_args();
echo static::NAME, " ".join(',', $args)." \n";
}
}
class B extends A
{
const NAME = 'B';
public static function test() {
echo self::NAME, "\n";
forward_static_call(array('A', 'test'), 'more', 'args');
forward_static_call( 'test', 'other', 'args');
}
}
B::test('foo');
function test() {
$args = func_get_args();
echo "C ".join(',', $args)." \n";
}
?>
以上示例会输出:
B B more,args C other,args