php命名空间

<?php


//spl_autoload_register:多次注册,队列执行

spl_autoload_register(function($className)
{
    $filePath='./'.str_replace('\\','/',$className).'.php';

    if(!file_exists($filePath)){
            throw new Exception('file not found.');
    }

    require_once $filePath;
});


$a=new \Demo\A();
$a->eat();
            
?>

./demo/A.php文件:

 

<?php


namespace demo;
class A{
	public function eat()
	{
			echo '吃';		
	}
}


?>

  

posted @ 2018-02-23 12:51  唔愛吃蘋果  阅读(93)  评论(0)    收藏  举报