You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

19 lines
502 B

  1. <?php
  2. /*
  3. * new时,若类未定义,回去别的文件找这个类
  4. * 类文件的名称需要与类名相同
  5. */
  6. spl_autoload_register
  7. (
  8. function($className)
  9. {
  10. include_once("./{$className}.php");
  11. }
  12. );
  13. $obj = new classA(); //因为classA在autoload.php中未定义,当new时,会自动调用spl_autoload_register函数,并且传递类名
  14. echo $obj->str.'<br>';
  15. $obj2 = new classB();
  16. echo $obj2->str.'<br>';
  17. ?>