PHP include_path设置技巧分享_PHP

WBOY
Release: 2016-06-01 12:16:10
Original
853 people have browsed it

1.include_path的意义

当时候函数include(),require(),fopen_with_path()函数来寻找文件时候.在不设置include_path的情况下,这些函数打开文件时候默认的是以web根目录去寻找.当设置include_path以后,这些php函数就会先在指定的include_path目录下面去搜索寻找.

其原理和window系统的环境变量相似,在window运行cmd命令的时候,输入一些cmd的命令之后系统会在其设定的环境变量里面去搜索这些命令是否存在,存在就可以执行.
PHP include_path设置技巧分享_PHP

2.include_path的设置
第一种方法:

修改php.ini文件中的include_path项。

include_path = .:/usr/local/lib/php:./include
第二个方法:

使用ini_set方法。
ini_set("include_path", ".:../:./include:../include");     

3.注意
zendframework include 设置 index.php

复制代码 代码如下:
set_include_path('.' .PATH_SEPARATOR.'../library/'
.PATH_SEPARATOR.'./application/models/'
.PATH_SEPARATOR.'./application/lib/'
.PATH_SEPARATOR.get_include_path());

PATH_SEPARATOR是一个常量,在Linux系统中是一个" : "号,Windows上是一个";"号。

所以编写程序时最好用常量 PATH_SEPARATOR 代替,否则如果系统从linux移植到win系统或反过来移植会出错!
get_include_path取得当前已有的环境变量,加上前面的设置就是新的系统include

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template