Correcting teacher:PHPz
Correction status:qualified
Teacher's comments:
<?php
namespace auto;
class autoLoad{
public static function load($class)
{
// 类名到类文件名
// 1.将路径分隔符替换
$path = str_replace('\\', DIRECTORY_SEPARATOR, $class);
$file = __DIR__ . '/' . $path . '.php';
if ( is_file($file) && file_exists($file))
{require $file;}
else {die($file . '不存在');}
}
}
<?php
include "autoLoad.php";
spl_autoload_register(["auto\autoLoad","load"]);
use admin\controller\Index;
use admin\model\User;
use admin\view\index\Hello;
$Index = new Index();
$User = new User();
$Hello = new Hello();
echo Index::show() . PHP_EOL;
echo User::show() . PHP_EOL;
echo Hello::show() . PHP_EOL;