類別和物件函式庫

call_user_method

(PHP3 >= 3.0.3 , PHP4)

call_user_method ---  在一個指定的物件上呼叫指定的方法

語法 : mixed call_user_method (string method_name, object obj [, mixed parameter [, mixed ...]])

說明 : 

從使用者定義的物件 obj來呼叫方法 method_name。下面是使用的範例,我們定義一個物件,說明如何使用call_user_method( )來間接地呼叫方法 print_info。

Example :

<?php

    class Country { 

               var $NAME; 

               var $TLD; 

               function Country($name, $tld) { 

                               $this->NAME = $name; 

                               $this->TLD = $tld; 

               }

               function print_info($prestr="") { 

                               echo $prestr."Country: ".$this->NAME."\n"; 

                               echo $prestr."Top Level Domain: ".$this->TLD."\n"; 

               } 

      } 

      $cntry = new Country("Peru","pe"); 

      echo "* Calling the object method directly\n"; 

      $cntry->print_info(); 

      echo "\n* Calling the same method indirectly\n"; 

      call_user_method ("print_info", $cntry, "\t");

?>

參考 : call_user_func( )


上一頁 首頁