Google

NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.7">

call_user_method

(PHP 3>= 3.0.3, PHP 4 )

call_user_method --  指定したオブジェクトのユーザーメソッドをコールする

説明

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

警告

PHP 4.1.0以降、call_user_method()関数は古い関数 となっています。代わりにarray(&$obj, "method_name")構文を指定して call_user_func()等を使用して下さい。

ユーザ定義のオブジェクト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() も参照下さい。