After two php include operations, the variable in the first include operation is invalid.

Source: Internet
Author: User
After two php include operations, the variables in the first include operation are invalid. directory structure + & nbsp; root & nbsp; index. php & nbsp; config. php & nbsp; after two php include operations, the variables in the first include operation are invalid.
Directory structure
+ Root
Index. php
Config. php
+ C
Index. php

Contents in root/config. php
$ Shell ['jquery '] = "jquery 1.4 ";
?>

Contents in root/index. php
Include "config. php ";
Print $ shell ['jquery '];
?>

Contents in root/c/index. php
Include "../index. php ";
?>

Access root/index. php and return
Jquery 1.4

Access root/c/index. php and return
Notice: Undefined variable: shell in H: \ software \ dev \ php \ xampp \ htdocs \ phptest \ index. php on line 3


Why does the variable become invalid after two include operations? How should we do it?
Thank you!
Share with php:
------ Solution --------------------
First, the resolution order is as follows:

1. is the file path an absolute path? Yes, including. resolution is complete. No, go to the next step.
2. the file path is a relative path (like your "../index. php ")? Yes. skip include_path and parse the relative path. No. next step.
PS: the base point of the relative path is always the "current working directory". that is, you have executed the script in this directory, not necessarily the directory where the script file exists.
For example, if you run 'php/var/www/index. php' in/root, the "current working directory" is/root instead of/var/www/, and/var/www is
Current_script_dir.
3. export de_path in php. ini, for example, ".: somepath: current_script_dir ". Split the list to be processed according to the DEFAULT_DIR_SEPARATOR constant (":" here ).
"." (Current working directory), "somepath (your custom directory)", "current_script_dir"
Append the included file names to these paths and try them one by one.

So your problem becomes



# Access root/c/index. php

Include "../index. php"; # execute step 2, include in/root/index. php

Include "config. php ";
# Run the third worker. The current working directory is/root/c, and current_script_dir is also/root/c,
# It is estimated that you have not customized include_path, so try to include/root/c/config. php without this file.

Print $ shell ['jquery '];
# Undefined variable
?>



This is my understanding. thank you for your comments and comments.

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.