「PHP」コールバック関数(call_user_func)を呼ぶサンプル
説明
call_user_func(callable $callback, mixed …$args): mixed
パラメータ callback で指定したユーザー定義のコールバック関数をコールします。
使用例
<?php
/*クラスAddrの定義*/
class Address
{
public function getMsg()
{
echo "study skill and become smart";
}
}
/*関数funcAの定義*/
function funcA($arr)
{
call_user_func($arr);
}
/*オブジェクトcftの生成*/
$cft = new Address();
//コールバック関数 変数1-オブジェクト 変数2-関数名
funcA(array($cft, "getMsg"));
?>
結果
study skill and become smart