Home > php教程 > php手册 > php模块自动加载简单版本autoload.php

php模块自动加载简单版本autoload.php

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-07 11:35:20
Original
1058 people have browsed it

php模块自动加载简单版本autoload.php
第一步:创建autoload.php,内容如下。

class autoload
{
public static function load($classname)
{
$filename=sprintf('%s.php',str_replace('\\','/',$classname));
if(is_file($filename)) require_once $filename;
}

}
spl_autoload_register(['autoload','load']);
第二步:创建测试模块QueryPhone内容如下。

namespace app;
class QueryPhone
{
public static function find($phone)
{
var_dump($phone);
}
}
第三步:创建测试api.php 文件测试,内容如下。

require_once 'autoload.php';
app\QueryPhone::find('1520032823823');
第四步:浏览器测试。
http://blog.popyelove.com/

http://blog.popyelove.com/?p=71

AD:真正免费,域名+虚机+企业邮箱=0元

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template