首页 | 源码下载 | 网站模板 | 网页特效 | 广告代码 | 网页素材 | 字体下载 | 书库 | 站长工具
会员投稿 投稿指南 RSS订阅
当前位置:主页>网络编程>PHP教程>资讯:PHPautoload PSR-0标准

PHPautoload PSR-0标准

www.jz123.cn  2013-07-29   来源:   站长家园    责任编辑(袁袁)    我要投递新闻

2
3
4
5
6
7
8
9
10
11
12
13
14
<?php
function autoload($className)
{
$className = ltrim($className, '\');
$fileName = '';
$namespace = '';
if ($lastNsPos = strripos($className, '\')) {
$namespace = substr($className, 0, $lastNsPos);
$className = substr($className, $lastNsPos + 1);
$fileName = str_replace('\', DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR;
}
$fileName .= str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php';
require $fileName;
}

 

强制约定

 

一个合格的名空间-类应当遵循这样的结构 <Vendor Name>(<Namespace>)*<Class Name>

A fully-qualified namespace and class must have the following structure <Vendor Name>(<Namespace>)*<Class Name>

每个名空间需要有一个顶级名空间 (“Vendor Name”)(提供者名称).

Each namespace must have a top-level namespace (“Vendor Name”).

每个名空间可以有任意多个子名空间

Each namespace can have as many sub-namespaces as it wishes.

从文件系统载入时,每个名空间分隔符将被转换为一个路径分隔符

Each namespace separator is converted to a DIRECTORY_SEPARATOR when loading from the file system.

类名中的每个下划线符( _ )将被转化为一个路径分隔符,名空间中的下划线符( _ )没有任何特定含义

Each _ character in the CLASS NAME is converted to a DIRECTORY_SEPARATOR. The _ character has no special meaning in the namespace.

一个合格的名空间-类所对应加载的文件必须是以.php结尾的

The fully-qualified namespace and class is suffixed with .php when loading from the file system.

Vendor Name(提供者名称)、名空间、类名中的字符可以是大小写的任意组合

Alphabetic characters in vendor names, namespaces, and class names may be of any combination of lower case and upper case.


上一篇:PHP和MySQL存储过程的实例演示 下一篇:PHP读取配置文件类(php,ini,yaml,xml)

评论总数:0 [ 查看全部 ] 网友评论


关于我们隐私版权广告服务友情链接联系我们网站地图