phpclass/클래스활용2000. 10. 10. 14:18
호환성
PHP3 >= 3.0.3, PHP4
기능
특정 객체에 포함된 사용자 정의 메소드 호출
형식
mixed call_user_method (string method_name, object obj [, mixed parameter [, mixed ...]])
설명
사용자 정의 객체인 obj로부터 method_name으로 참조되는 해당 메소드를 호출합니다. 아래에 있는 활용 예제에서 클래스를 정의하고, 객체를 인스턴스화하고, print_info 메소드를 간접적으로 호출하기 위해 call_user_method()를 이용합니다.
[code php;gutter:false] <?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");

?> [/code]
참고
call_user_func()

Posted by 방글24