If you have any questions about the php file reference, please take a look. thank you.

Source: Internet
Author: User
I have a question about the PHP file reference. could you please take a look at it? thanks for a PHP question. could you please take a look at it,
I define a constant in index. php.
Define ('script', 'index ');
And reference the file title. php.
Require 'Title. php ';
In title. php, I did not reference the index. php file, but I can also print the constant value in index. php.
Echo SCRIPT; // result index
Can the referenced php file use constants and variables in the referenced php file?

For example, index. php references title. php. Can I use the constants and variables defined in index. php?


Reply to discussion (solution)

Yes. pay attention to the order. Define and then use

If you directly browse http: // localhost/title. php, the index cannot be printed, and the printed value is SCRIPT.

At that time, if you browse http: // localhost/index. php. it will be printed and the value is index.

In fact, I personally simply understood the reference and copied the code directly!

In

Require 'Title. php ';
The previously defined global variables or constants can be accessed in title. php.

Define ('script', 'index ');

Define defines global constants and can be accessed anywhere

After trying, you can use the constants defined in the reference page on the cited page, whether before or after the referenced statement.
However, you cannot use the variables on the "reference page", whether before or after a reference statement.

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.