首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 企业软件 > 行业软件 >

_autoload自动加载种文件 和spl_autoload_register函数

2012-11-12 
__autoload自动加载类文件 和spl_autoload_register函数--------clsdemo.php文件--------?phpclass clsde

__autoload自动加载类文件 和spl_autoload_register函数

--------clsdemo.php文件--------<?php  class clsdemo {      public function show(){          echo "test";      }  }  ?> ---------index.php文件---------//不需要include require单独引用 php5函数 会在IO文件时有一定的性能消耗 <?php  function __autoload($class_name) {      require_once $class_name . '.php';  }    $test  = new clsdemo();  $test->show();  //显示是test  ?>---------spl.php文件-----------<?php  function loader($class_name) {      require_once $class_name . '.php';  }   spl_load_register('loader');//自动加载的时候不调用__autoload()而调用自己的函数或类方法  $test  = new clsdemo();  $test->show();  //显示是test  ?>-----------调用类方法------------<?phpclass Loader{    public static function loadClass($class_name)    {require_once $class_name . '.php';      }}spl_load_register(array('Loader', 'loadClass'));?>

热点排行