spl_autoload_register

test.php

<?php

class MyClass {
public static function autoload($className) {
require ($className.".php");
}

public static function autoload2($className) {
require ($className."test.php");
}
}

spl_autoload_register(array('MyClass', 'autoload2'));
spl_autoload_register(array('MyClass', 'autoload'));

spl_autoload_register(array('MyClass', 'autoload'),true,true);   //注意第三个参数..如果为true,会先执行他

 

$hass = new hass();
echo $hass->name;  //222
?>

 

hasstest.php

<?php

class hass {
public $name = "222";
}

?>

 

hass.php

<?php

class hass {
public $name = "1";
}

?>

posted @ 2014-08-24 20:20  zhepama  阅读(360)  评论(0编辑  收藏  举报