call_user_method

(PHP 3 >= 3.0.3, PHP 4, PHP 5)

call_user_method --  呼叫特定對象的會員方法〔已停用〕

描述

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

警示

call_user_method() 函數從 PHP 4.1.0 開始已經停用,使用 call_user_func() 函數和 array(&$obj, "method_name") 語法代替。

從會員定義的 obj 物件中呼叫 method_name 所指的方法。下邊是用法示例,我們定義了一個類,接著建立了一個物件案例,然後使用 call_user_method() 間接呼叫它的 print_info 方法。

<?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_array()call_user_func()call_user_method_array()