A little doubt about PHP function Set_include_path

Source: Internet
Author: User
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 ');

Code as above, p_s is Path_separator

Problem:
Why do I have to add '. ' Before each path? What about this one?

I checked the manual, there is one in the comments, which means it is necessary to add it, but the reason is still unknown ....

Joel at pittet Dot ca17-nov-2010 02:46

Seems Set_include_path wasn ' t working for me.

The problem was I didn ' t has.: In my Include_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 ');

Code as above, p_s is Path_separator

Problem:
Why do I have to add '. ' Before each path? What about this one?

I checked the manual, there is one in the comments, which means it is necessary to add it, but the reason is still unknown ....

Joel at pittet Dot ca17-nov-2010 02:46

Seems Set_include_path wasn ' t working for me.

The problem was I didn ' t has.: In my Include_path
Which seemed to stop the Set_include_path ().

"." Represents the current directory, ":" is a delimiter of two different include path values.

Include_path does not contain ".", PHP encounters an include ($file), require ($file) statement when it is not in the current directory (if you are accessing/var/www/html/my_app/ index.php, the current directory is/www/html/my_app/) looking for $file, go directly to other include_path search.

Include_path "." To see if you will not use relative paths to include files in the current directory, the PHP engine is not forced.

Real-Machine testing

Tests have shown that either the INI or the code set_include_path () can be changed without the "."
Figure 1:ini Setting the Include_path

Include_path is not set in Figure 2:ini, Set_include_path () is called in the code

Figure 3:ini Setting include_path, calling Set_include_path () in the code

Figure 4:ini Setting Include_path (containing the current directory), calling Set_include_path () in the code

In addition, if the code does not call Set_include_path (), the INI does not set the include_path, the direct echo get_ include_path (), will output "."

Also, the first time the test, first Set_include_path ("/var"), and then Echo Get_include_path (), incredibly nothing output, but I can no longer reproduce this phenomenon, Not sure if test.php belonged to root with sudo (theoretically not, but failed to reproduce)

Extended Reading

For more details on the include, you can read an article I wrote in the previous two weeks, "About PHP class library auto-loading": http://weibo.com/1779910713/zg59ehZCd, Page Two, the first paragraph.

The goods are estimated to be direct set_include_path ("/some/path"); So there was an error in the include (file under the current directory).

This is similar to executing files under the current directory under Linux./error.

If you use Get_include_path () to spell it, you don't need it. You can echo the value of Get_include_path () and see that it contains the "."

  • 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.