Some Questions about the PHP function set_include_path

Source: Internet
Author: User
Set_include_path (get_include_path (). p_S. & #039 ;. & #039 ;. p_S. $ siteConf [& #039; baseDir & #039;]); set_include_path (get_include_path (). p_S. & #039 ;. & #039 ;. p_S. $ siteConf [& #039; libDir & #039;]); set_include_path (get_include_path (). P _... set_include_path (get_include_path (). p_S. '. '. p_S. $ siteConf ['basedir']);
Set_include_path (get_include_path (). P_S. '. P_S. $ siteConf ['libdir']);
Set_include_path (get_include_path (). P_S. '. P_S. $ siteConf ['basedir']. 'app ');

The code above, P_S is PATH_SEPARATOR

Problem:
Why should '.' be added before each path?

I checked the manual and found this one in the comments. This indicates that it is still necessary to add it, but the reason is still unknown ....

Joel at pittet dot ca17-Nov-2010

Seems set_include_path wasn't working for me.

The problem was I didn't have.: in my own de_path
Which seemed to stop the set_include_path ().

Reply content:

Set_include_path (get_include_path (). P_S. '. P_S. $ siteConf ['basedir']);
Set_include_path (get_include_path (). P_S. '. P_S. $ siteConf ['libdir']);
Set_include_path (get_include_path (). P_S. '. P_S. $ siteConf ['basedir']. 'app ');

The code above, P_S is PATH_SEPARATOR

Problem:
Why should '.' be added before each path?

I checked the manual and found this one in the comments. This indicates that it is still necessary to add it, but the reason is still unknown ....

Joel at pittet dot ca17-Nov-2010

Seems set_include_path wasn't working for me.

The problem was I didn't have.: in my own de_path
Which seemed to stop the set_include_path ().

"." Indicates the current directory. ":" Is the delimiter of two different include path values.

Include_path does not contain ".". When PHP encounters the include ($ file) and require ($ file) statementNoIn the current directory (if/var/www/html/my_app/index is accessed. php, the current directory is/www/html/my_app/) to find $ file, directly go to other include_path to find.

If "." is not added to include_path, it depends on whether you will use a relative path to include files in the current directory. The PHP engine is not mandatory.

Real Machine Test

The test shows that "." is not included in both the ini modification and the set_include_path () in the code "."
: Set include_path in ini

: Include_path is not set in ini. The Code calls set_include_path ()

: Set include_path in ini, and call set_include_path () in the code ()

: Set include_path (including the current directory) in ini, and call set_include_path () in the code ()

In addition, if set_include_path () is not called in the code, and include_path is not set in ini, echo get _ include_path () directly and output "."

In addition, during the first test, set_include_path ("/var") and then echo get_include_path (), there was no output, but I could not reproduce this phenomenon any more. I'm not sure if it was the test at the time. php is because sudo is used by root (theoretically not, but it cannot be reproduced)

Additional reading

For more details about include, refer to the article I wrote in the previous two weeks: http://weibo.com/1779942613/zg59ehzcd, page 2 and section 1.

This item is estimated to be set_include_path ("/some/path") directly, so an error occurs when include (the file in the current directory.

This is similar to running the file in the current directory in linux without having to upload./will cause an error.

If you use get_include_path () to fight, this is not required. You can echo the value of get_include_path () to see if it already contains "."

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.