首页 > Web开发 > 详细

PHP中使用set_include_path动态设置文件加载扫描路径

时间:2014-11-04 00:20:10      阅读:266      评论:0      收藏:0      [点我收藏+]

/index.php
/include/config.php

下面是index.php

<?php 
$path = ‘/usr/lib/pear‘; 
set_include_path(get_include_path() . PATH_SEPARATOR . $path);
//设置后的include_path变为类似/usr/lib/function;/usr/lib/pear 
include("config.php"); //先搜索当前目录->搜索get_include_path()列出的路径
?>

输出一下

<?php 
  echo get_include_path();
?>

结果

/user/tpls;/usr/lib/function;/usr/lib/pear;

这类似于java中的类加载路径,加载一个文件时,在扫描当前目录之后,将在上述3个路径下查找。

PHP中使用set_include_path动态设置文件加载扫描路径

原文:http://my.oschina.net/ososchina/blog/340352

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!