复制代码namespace AcmeController;
class HomeController
{
// ...
}
// 自动加载器
spl_autoload_reGISter(function ($class) {
$class = ltrim($class, "\");
$file = "";
if ($lastNsPos = strripos($class, "\")) {
$namespace = substr($class, 0, $lastNsPos);
$class = substr($class, $lastNsPos + 1);
$file = str_replace("\", DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR;
}
$file .= str_replace("_", DIRECTORY_SEPARATOR, $class) . ".php";
if (file_exists($file)) {
require $file;
return true;
}
return false;
});
// 类自动加载
$instance = new AcmeControllerHomeController();
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
php语法对index.php首页进行判断(根据需要显示不同页面)
上面是“php语法中PSR-4自动加载语法”的全面内容,想了解更多关于 php入门 内容,请继续关注web建站教程。
当前网址:https://m.ipkd.cn/webs_14990.html
声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!