[关闭]
@Chiang 2020-01-08T11:09:29.000000Z 字数 949 阅读 547

forward_static_call

PHP


forward_static_call — Call a static method

说明

  1. forward_static_call ( callable $function [, mixed $parameter [, mixed $... ]] ) : mixed

Calls a user defined function or method given by the function parameter, with the following arguments. This function must be called within a method context, it can't be used outside a class. It uses the late static binding.

参数

function

The function or method to be called. This parameter may be an array, with the name of the class, and the method, or a string, with a function name.

parameter

Zero or more parameters to be passed to the function.

返回值

Returns the function result, or FALSE on error.

范例

  1. <?php
  2. class A
  3. {
  4. const NAME = 'A';
  5. public static function test() {
  6. $args = func_get_args();
  7. echo static::NAME, " ".join(',', $args)." \n";
  8. }
  9. }
  10. class B extends A
  11. {
  12. const NAME = 'B';
  13. public static function test() {
  14. echo self::NAME, "\n";
  15. forward_static_call(array('A', 'test'), 'more', 'args');
  16. forward_static_call( 'test', 'other', 'args');
  17. }
  18. }
  19. B::test('foo');
  20. function test() {
  21. $args = func_get_args();
  22. echo "C ".join(',', $args)." \n";
  23. }
  24. 输出:
  25. B
  26. B more,args
  27. C other,args
  28. ?>
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注