You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
20 lines
502 B
20 lines
502 B
<?php
|
|
/*
|
|
* new时,若类未定义,回去别的文件找这个类
|
|
* 类文件的名称需要与类名相同
|
|
*/
|
|
|
|
spl_autoload_register
|
|
(
|
|
function($className)
|
|
{
|
|
include_once("./{$className}.php");
|
|
}
|
|
);
|
|
|
|
$obj = new classA(); //因为classA在autoload.php中未定义,当new时,会自动调用spl_autoload_register函数,并且传递类名
|
|
echo $obj->str.'<br>';
|
|
|
|
$obj2 = new classB();
|
|
echo $obj2->str.'<br>';
|
|
?>
|