When I run phpinfo()
and look by the Configuration
category under PHP Core
, I see a directive titled include_path
, with a local value and a master value.
In this case, my local value is set to
.: ./include: ../include: /usr/share/php: /usr/share/php/smarty: /usr/share/pear
and my master value is set to
.: /usr/share/php: /usr/share/pear: /usr/share/php/pear: /usr/share/php/smarty
The reason I am trying to learn how this works is because there is a file in the system I am working on titled Smarty.class.php
, which I'm sure sounds very familiar to anyone who uses Smarty Templating Engine.
One of the PHP files has the following includes:
require_once("Smarty.class.php"); require_once("user_info_class.inc");
The file user_info_class.inc
is in the same directory as the file making the include, which makes perfect sense to me, and is the way that I've always referenced files. I decided that I wanted to open up the Smarty.class.php file and had assumed it would be in the same directory, but it was not.
After doing a bit of digging, I discovered those php_ini
variables, and was finally able to locate the file in the directory usr/share/php/smarty/
.
So it would seem that when making an include, it follows some sort of order between the Loc开发者_运维百科al and Master values for the include_path
.
Assuming that my deductions were correct thus far, can someone explain the order in which PHP searches for the files to be included?
The global value is basically what's set in php.ini. The local value is what's currently being used. The local value completely overwrites the master value.
According to the manual, PHP checks the paths in the order that they are specified in the include_path setting: http://php.net/manual/en/ini.core.php#ini.include-path
精彩评论