Require_once a strange phenomenon, everybody, look.

Source: Internet
Author: User
Require_once a strange phenomenon, everybody look down
I am in the root directory of the file require_once ("test/1.php"); Then in 1.php require_once ("2.php");
Case 1, if my root directory exists 2.php program will go to reference the root directory of 2.php
Case 2, if my root directory does not exist 2.php, the program will also refer to the test directory of 2.php
Do not know why there is a situation of 2, we have encountered it, what is the reason?
Require_once is not the first page in the main path?



------to solve the idea----------------------
Include (include_once, require, require_once) to execute the file as the benchmark
Find files by the path indicated by include_path
Generally include_path = ".:/ Path1:/path2 "(UNIX) or include_path =".; \ Path1;\path2 "(window)
The.,/path1,/path2 .... The Sequential lookup

So the order of the search is: the directory where the program is executed, the directory where the files are contained, and the other directories specified by include_path

The advantage of this design is that you can change some behavior of the original project without having to modify the original project

index.php (require_once ("test/1.php");)
test/1.php (require_once ("2.php");)
test/2.php
2.php (this 2.php will replace test/2.php)
  • 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.