spl_autoload_register 注册给定的函数作为 __autoload 的实现 官方地址:http://php.net/manual/zh/function.spl-autoload-register.php 我的测试 定义三个文件test.php test1.php test2.php test.php ? phpspl_autoload_register( ' autoLoad1 ' );test1::
spl_autoload_register — 注册给定的函数作为 __autoload 的实现
官方地址:http://php.net/manual/zh/function.spl-autoload-register.php
我的测试
定义三个文件test.php test1.php test2.php
test.php
<span>php spl_autoload_register(</span><span>'</span><span>autoLoad1</span><span>'</span><span>); test1::test();<br>echo "<br>"; test2::test(); function autoLoad1($</span><span>class</span><span>) { require $</span><span>class</span>.<span>'</span><span>.php</span><span>'</span><span>; }</span>
test1.php
<span>php </span><span>class</span><span> test1 { </span><span>static</span> <span>public</span><span> function test() { echo __FILE__; } }</span>
test2.php
<span>php </span><span>class</span><span> test2 { </span><span>static</span> <span>public</span><span> function test() { echo __FILE__; } } </span>
运行test.php