Correction status:qualified
Teacher's comments:当天作业不要一个个分开交, 请合并一并提交
自动加载
文件jz.php
<?php namespace _0802; //require __DIR__.'/inc/Test1.php'; //require __DIR__.'/inc/Test2.php'; //echo \inc\Test1::get().'<br>'; //echo \inc\Test2::get().'<br>'; spl_autoload_register(function ($ClassName){ $path=str_replace('//','/',$ClassName); $path=__DIR__.'\\'.$path.'.php'; if(file_exists( $path)){ require $path; } }); echo \inc\Test1::get(); echo '<br>'; echo \inc\Test2::get();
点击 "运行实例" 按钮查看在线实例
Test1.php
<?php namespace inc; class Test1 { public static function get() { return __CLASS__.'被加载成功'; } }
点击 "运行实例" 按钮查看在线实例
Test2.php
<?php namespace inc; class Test2 { public static function get() { return __CLASS__.'被加载成功'; } }
点击 "运行实例" 按钮查看在线实例