PHP类的函数:__call,__callStatic基于php5.3以上

_call和___callStatic这两个函数是php类的默认函数,

__call() 在一个对象的上下文中,如果调用的方法不能访问,它将被触发

__callStatic() 在一个静态的上下文中,如果调用的方法不能访问,它将被触发


<?php
class MethodTest {
public function __call($name, $arguments
) {
// Note: value of $name is case sensitive.
echo
"Calling object method '$name' "
. implode(', ', $arguments). "\n"
;
}

/**   As of PHP 5.3.0   */
public static function __callStatic($name, $arguments
) {
// Note: value of $name is case sensitive.
echo
"Calling static method '$name' "
. implode(', ', $arguments). "\n"
;
}
}

$obj = new MethodTest;
$obj->runTest('in object context'
);

MethodTest::runTest('in static context'); // As of PHP 5.3.0
?>

运行结果:
Calling object method ‘runTest’ in object context

Calling static method 'runTest' in static context
Name(required)
E-Mail(required)
Website(required)
关于本人

本人虎子,今年24,正好本命年

分类