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.