顾名思义,set_include_path函数,是用来设置include的路径的。
比如,在正常include时,我需要指定绝对路径:
include(ROOT_PATH . 'config/config.php');
include(ROOT_PATH . 'lib/pdo.class.php');
include(ROOT_PATH . 'global/function.php');
如果我们用send_inclue_path设置后,
// Set include_path
$include_path[] = '.' ;
$include_path[] = ROOT_PATH . 'lib' ;
$include_path[] = ROOT_PATH . 'config' ;
$include_path[] = ROOT_PATH . 'global' ;
$include_path[] = get_include_path();
set_include_path(implode(PATH_SEPARATOR, $include_path));
那我第一段代码就不需要再写路径:
include('config.php');
include('pdo.class.php');
include('function.php');
设置了include路径配合上一篇的spl_autoload_register函数,就可以实现不同目录的autoload