コード
test.php
<?php
class Test{
public function show($param){
echo "test: ".$param.PHP_EOL;
}
}
$test = new Test();
array_map(array($test, "show"), array(1,2,3));
class Test2{
public function show($param){
echo "test: ".$param.PHP_EOL;
}
public function show2($param){
echo "test2: ".$param.PHP_EOL;
}
//ここで->show2を指定したらそっちが呼ばれる
public function __invoke($param){
return $this->show($param);
}
}
$test2 = new Test2();
array_map($test2, array(4,5,6));
実行
test: 1
test: 2
test: 3
test: 4
test: 5
test: 6