class SportObject9{
public function myDream(){
echo '调用的方法存在,直接执行此方法。
';
}
public function __call($name, $arguments)
{
// TODO: Implement __call() method.
echo '方法不存在,则执行__call()方法。
';
echo '方法名为:'.$name.'
';
echo '参数有:';
echo '
';
print_r($arguments);
}
}
$exam=new SportObject9();
$exam->myDream();
$exam->mDream('how','what','why');
/**
* 调用的方法存在,直接执行此方法。
方法不存在,则执行__call()方法。
方法名为:mDream
参数有:
Array
(
[0] => how
[1] => what
[2] => why
)
*/
class SportObject10{
private $type='DIY';
public function __toString()
{
return $this->type;//方法返回私有变量$tpye的值
// TODO: Implement __toString() method.
}
}
$mycomputer=new SportObject10();
echo '对象$mycomputer的值为:'.$mycomputer.'
';
/**
* 对象$mycomputer的值为:DIY
*/
/**
* 通常用include()或require()函数在一个php文件中引入类文件。‘
* require('a.php');
* $a=new a();
*/
function __autoload($classname){
$class_path=$classname.'php文件路径';
if (exists($class_path)){
include_once ($class_path);
}else{
echo '类路径错误';
}
}