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
廣告