call_user_method
(PHP 4, PHP 5)
call_user_method — 특정 객체의 사용자 메소드를 호출한다 [낡았음]
설명
mixed call_user_method
( string $method_name
, object $obj
[, mixed $parameter
[, mixed $...
]] )
Warning
이 call_user_method() 함수는 PHP 4.1.0 부터 낡은 함수가 되었다. 대신 array(&$obj, "method_name") 문법을 갖는 call_user_func_array() 변종(variety)을 사용하도록 한다.
사용자 선언된 obj 객체에서 method_name 으로 참조되는 메소드를 호출한다. 아래 예제코드를 보면, 클래스를 선언하고 객체를 생성하고 print_info 메소드를 간접적으로 호출하기 위해 call_user_method() 함수를 사용하는 것을 볼수 있다.
<?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() 참고.