php语法中PSR-4自动加载语法

666 ℃
复制代码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首页进行判断(根据需要显示不同页面)

html文本如何读取数据库代码示例

php表单提交报错显示适当的错误消息代码

php语法中sleep函数的基本用法

利用php语法中NOT IN排除多个字段功能

标签: php语法, PSR-4

上面是“php语法中PSR-4自动加载语法”的全面内容,想了解更多关于 php入门 内容,请继续关注web建站教程。

当前网址:https://m.ipkd.cn/webs_14990.html

声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!

mysql语法如何删除第一行数据
vue红包摇一摇抽奖活动代码
vuejs安装Vant有赞移动端组件库
网站改版如何做才能降低损失
营销人士关心的PR传播是什么意思?(图文)