PSR-0规范1.命名空间必须与绝对路径一致 2.类名首字母必须大写 3.除入口文件外,其它.php必须只有一个类。
1.全部使用命名空间
2.所有php文件必须自动载入,不能有include/require
3. 单一入口
目录 
控制器中的index.php
<?phpnamespace AppControllerHome;class Index{
static function test()
{
echo '我是控制器';
}
}Loader.php
<?php/**
* User: baldy
* CreateTime: 2018/2/27 下午5:27
* Description:
*/namespace IMooc;class Loader{
static function autoload($class)
{
$file = BASEDIR.'/'.str_replace('\','/',$class).'.php'; require $file;
}
}Object1.php
立即学习“PHP免费学习笔记(深入)”;
<?phpnamespace IMooc;class Object1{
static function test(){
echo "我是Object";
}
}index.php
<?phpdefine('BASEDIR',__DIR__);
include BASEDIR . '/IMooc/Loader.php';
spl_autoload_register('\IMooc\Loader::autoload');
IMoocObject1::test();
AppControllerHomeIndex::test();我是Object我是控制器
相关推荐:
PHP的PSR-0标准利用namespace来做autoloading
以上就是PHP面向对象PSR-0规范详解的详细内容,更多请关注php中文网其它相关文章!
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号