PHP - forward_static_call()



forward_static_call() 函数可以调用静态方法。

语法

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

forward_static_call() 函数可以调用由函数参数给定的用户定义函数或方法。它必须在方法上下文中调用,不能在类外部使用。它可以使用延迟静态绑定。

示例

<?php
   class Beer {
      const NAME = 'Beer!';
      public static function printed(){
         echo 'static Beer:NAME = '. static::NAME . "\n";
      }
   }

   class Ale extends Beer {
      const NAME = 'Ale!';
      public static function printed(){
         forward_static_call(array('parent','printed'));
         call_user_func(array('parent','printed'));

         forward_static_call(array('Beer','printed'));
         call_user_func(array('Beer','printed'));
       }
   }
   Ale::printed();
   echo "\n";
?>

输出

static Beer:NAME = Ale!
static Beer:NAME = Ale!
static Beer:NAME = Ale!
static Beer:NAME = Beer!
php_function_reference.htm
广告