首页 > 代码库 > PHP中使用set_include_path动态设置文件加载扫描路径
PHP中使用set_include_path动态设置文件加载扫描路径
/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动态设置文件加载扫描路径
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。