function initialize()
{
    set_include_path(get_include_path().PATH_SEPARATOR . "core/");
    set_include_path(get_include_path().PATH_SEPARATOR . "app/");
    set_include_path(get_include_path().PATH_SEPARATOR . "admin/");
    set_include_path(get_include_path().PATH_SEPARATOR . "lib/");
    set_include_path(get_include_path().PATH_SEPARATOR . "include/");
    set_include_path(get_include_path().PATH_SEPARATOR."data/");
    set_include_path(get_include_path().PATH_SEPARATOR."cache/");
}
    这样它的路径就成了:
    .;C:\php5\pear;core/;app/;admin/;lib/;include/;data/;cache/
    哎,我们发现前面还有个.;C:\php5\pear;这到底是怎么回事呢,其实我们如果什么也不写直接先输出一下include_path的默认值,就会发现它就是.;C:\php5\pear;它可以允许随便去一个引入文件。
    如果再加载了许多文件夹的话,我们直接写文件名就可以了!
   但是正如我最开始那个问题一样,为什么我们公司的代码和人家的就不一样呢,原来,如果我就写一个
          set_include_path(dirname(__FILE__));
   然后去引入其他文件夹的文件,就会报错,说在我指定的这个文件夹内找不到。
      首先,我们先用另外一种方法输出一下:
       <?php
           set_include_path(dirname(__FILE__));
           $include_value = ini_get('include_path');
           echo $include_value;
       ?>
      结果是:D:\AppServ\www
      我如果去www下找test4.php这个文件,则没有报错
      include("test4.php");
      但是我如果去找
      include("test1.php");
      就会报错:
      Warning: include() [function.include]: Failed opening 'test1.php' for inclusion (include_path='D:\AppServ\www') in D:\AppServ\www\test.php on line 6
     而且我们还发现
.;C:\php5\pear;已经被替换掉了。所以我们在使用的时候,如果不是仅在一个文件夹下引入文件,我们就需要在前面加上get_include_path().PATH_SEPARATOR .
     解释一下:
            get_include_path()是获取当前include_path的默认值
            PATH_SEPARATOR 是个常量,是include的路径分界符合,在window上是;在unix和Linux上是:
     最后,我还要说一下,其实我们也可以通过另外一种方法:即最原始的:
           ini_set('include_path', '目录名'); 
    另外,需要注意的两点就是:
           如果在指定的目录下找不到所要求包含的文件,而在当前页面目录下正好存在这个名称的文件时,则默认引入当前目录下的该文件。
           当指定了多个目录为 include_path ,而所要求包含的文件在这几个目录都有相同名称的文件存在时,php选择使用设定 include_path 时排位居前的目录下的文件。

set_include_path() &&get_include_path()用法的更多相关文章

  1. set_include_path和get_include_path用法详解

    首先set_include_path这个函数呢,是在脚本里动态地对PHP.ini中include_path进行修改的.而这个include_path呢,它可以针对下面的include和require的 ...

  2. 【php】set_include_path和get_include_path用法详解

    目的:在框架中方便加载文件 参考:http://blog.sina.com.cn/s/blog_4ce89f200100twbl.html 如果我们没有设置这个值,可能我们需要写一些完全的路径:    ...

  3. php 文件路径设置 set_include_path(); get_include_path();

    <?php set_include_path($string); //设置路径 get_include_path(); // 获取当前的路径 //例如:文件路径为: //D:/phpweb/de ...

  4. set_include_path()的用法

    朋友们 开发的时候 ,总会 遇到 include_once()的情况.有时候,我们需要大量的引用文件,但是被引用文件的路径有时候是个问题.  我们可以把 经常要引用 的文件,放在一个 文件夹中,我们取 ...

  5. php get_include_path();是干嘛的、??还有set_include_path();/?????

    首先 我们来看这个全局变量:__FILE__ 它表示文件的完整路径(当然包括文件名在内) 也就是说它根据你文件所在的目录不同,有着不同的值:当然,当它用在包行文件中的时候,它的值是包含的路径: 然后: ...

  6. PHP中spl_autoload_register()函数用法实例详解

    本文实例分析了PHP中spl_autoload_register()函数用法.分享给大家供大家参考,具体如下: 在了解这个函数之前先来看另一个函数:__autoload. 一.__autoload 这 ...

  7. set_include_path详细解释

    zendframework的示例index.php里有这样一句 set_include_path('.' . PATH_SEPARATOR . '../library/'. PATH_SEPARATO ...

  8. set_include_path — 设置 include_path 配置选项为当前脚本设置 include_path 运行时的配置选项。

    说明 string set_include_path ( string $new_include_path ) 为当前脚本设置 include_path 运行时的配置选项. 参数 new_includ ...

  9. php set_include_path

    string set_include_path ( string $new_include_path ) 为当前脚本设置 include_path 运行时的配置选项. Example #2 添加到in ...

随机推荐

  1. MIPS——分支语句

    有关指令 li $t1,immediate #load immediate,立即数可正可负 la $t1,address #load address move $t1,$t2 #move $t2 to ...

  2. CAD交互绘制云线批注(网页版)

    js中实现代码说明: 动态拖放时的绘制事件: function DoDynWorldDrawFun(dX,dY,pWorldDraw,pData) { //自定义实体的GUID标识符 var sGui ...

  3. OracleDBConsole启动不了

    今天要用OEM,然后去打开OracleDBConsoleXXX, 提示说什么么么2,然后就各种百度...最后发现...有断了网络连接之后就可以把它启动了...简直惨,不知道这是什么原理,还有Oracl ...

  4. POI读word doc 03 文件的两种方法

    Apache poi的hwpf模块是专门用来对word doc文件进行读写操作的.在hwpf里面我们使用HWPFDocument来表示一个word doc文档.在HWPFDocument里面有这么几个 ...

  5. SQLyog连接数据库 提示错误plugin caching_sha2_password could not be loaded

    1.打开mysql cmd 2.执行语句 ALTER USER 'root'@'localhost' IDENTIFIED BY 'password' PASSWORD EXPIRE NEVER; # ...

  6. [POJ] 3362 Telephone Lines

    Telephone Lines Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7978 Accepted: 2885 Descr ...

  7. verilog behavioral modeling--sequential and parallel statements

    1.Sequential statement groups the begin-end keywords: .group several statements togethor .cause the ...

  8. 查找闲置ip

    首先ping 一下该网段的广播地址,如ping 192.168.0.255 ,然后使用arp -a就可以查看到那些地址是被使用的,以及网卡的mac值.剩余的是暂时还未被使用的,当然没开机的机器就看不出 ...

  9. 关于priority_queue的一些说明

    参考GGBeng 相关定义 优先队列容器与队列一样,只能从队尾插入元素,从队首删除元素.但是它有一个特性,就是队列中最大的元素总是位于队首,所以出队时,并非按照先进先出的原则进行,而是将当前队列中最大 ...

  10. STM32中如何对printf函数重定向

    通过USART1向计算机的串口调试助手打印数据,或者接收计算机串口调试助手的数据,接下来我们现STM32工程上的printf()函数,方便用于程序开发中调试信息的打印. 方法一:使用MicroLIB库 ...