Jamers Posted January 5, 2016 Report Share Posted January 5, 2016 PHP5开始导入自动加载(autoload)功能,闲来无事测试一下,以便日后使用,留下测试代码。 t1.php <?php function aload($c) { var_dump($c); if (file_exists($c.'.class.php')) { include_once($c.'.class.php'); return true; }else{ return true; } } spl_autoload_register('aload'); $t = new test(); echo $t->test1('Jamers'); $d = new TB(); var_dump($d); ?> test.class.php <?php class test { function test1($t) { return "Res:{$t}"; } } ?> 运行结果: string(4) "test" Res:Jamersstring(2) "TB" <br /> <b>Fatal error</b>: Class 'TB' not found in <b>test\t1.php</b> on line <b>16</b><br /> Link to comment Share on other sites More sharing options...
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now