Correcting teacher:PHPz
Correction status:qualified
Teacher's comments:
a. 类名和文件名的相互对应(同名,类名采用大驼峰的原则,首字母大写);
b. 类空间和类文件路径的一致。
splautoloadregister(function($class){
// 将空间名和文件路径协调起来
$path = str_replace(“\“,DIRECTORY_SEPARATOR,$class);
$file = __DIR .’/‘ . $path.”.php”;
if(is_file($file) && file_exists($file)){
require $file;
}else{
die(“文件不存在”);
}
});
use admin\controller\Index;
use admin\model\User;
use admin\view\index\Hello;
文件的架构如图:
<?php
namespace admin\controller;
class Index {
public static function controllerhere()
{
echo __FILE__;
}
}
?>
<?php
namespace admin\model;
class User{
public static function userhere()
{
echo __FILE__;
}
}
?>
<?php
namespace admin\view\index;
class Hello{
public static function hellohere()
{
echo __FILE__;
}
}
?>
<?php
namespace core;
class Main {
public function __construct()
{
}
public static function show(){
spl_autoload_register(function($class){
echo $class;
echo PHP_EOL;
// 将空间名和文件路径协调起来
$path = str_replace("\\",DIRECTORY_SEPARATOR,$class);
$file = __DIR__ .'/' . $path.".php";
if(is_file($file) && file_exists($file)){
require $file;
}else{
die("文件不存在");
}
});
}
}
Main::show();
use admin\controller\Index;
use admin\model\User;
use admin\view\index\Hello;
echo Index::controllerhere().PHP_EOL;
echo User::userhere().PHP_EOL;
echo Hello::hellohere().PHP_EOL;
?>