php模块自动加载简单版本autoload.php
Jun 07, 2016 am 11:35 AMphp模块自动加载简单版本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元

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Learn about introductory code examples for Python programming

PHP variables in action: 10 real-life examples of use

From beginner to proficient: Code implementation of commonly used data structures in Go language

How to use PHP to write inventory management function code in the inventory management system

Go language programming examples: code examples in web development

Java implements simple bubble sort code

Huawei Cloud Edge Computing Interconnection Guide: Java code examples to quickly implement interfaces

Guidance and Examples: Learn to implement the selection sort algorithm in Java
