PHP7中文手册2018 带注释 最新chm版
__call()函数是php类的默认魔法函数,__call() 在一个对象的上下文中,如果调用的方法不存在的时候,它将被触发:
<?php
class MethodTest {
public function __call($name, $arguments) {
// Note: value of $name is case sensitive.
echo "Calling object method '$name' "
. implode(', ', $arguments). "\n";
}
}
$obj = new MethodTest;
$obj->runTest('in object context');
运行结果:
Calling object method 'runTest' in object context
<?php
class MethodTest {
public function __call($name, $arguments) {
// Note: value of $name is case sensitive.
echo "Calling object method '$name' "
. implode(', ', $arguments). "\n";
}
}
$obj = new MethodTest;
$obj->runTest('in object context');
运行结果:
Calling object method 'runTest' in object context
转载请注明:谷谷点程序 » PHP魔法函数:__call()