Constants and includes

Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy.
This forum is not for asking programming related questions.

Moderator: General Moderators

Post Reply
burstgoof
Forum Newbie
Posts: 2
Joined: Thu Nov 18, 2004 10:25 am

Constants and includes

Post by burstgoof »

Something really weird happening...PHP 5.....
I include a file at the top of a script, the included file defines some constants.
Then later on in the script, I include another file that has some lines that echo the values of those defined constants. Thing is, the included file doesn't have access to those constants.....
I proved it by using get_defined_constants from within the included code...and the constants array does NOT contain a USER array.
As I understand it, included files should have access to vars of all scopes that have been defined in the original script up to that point.
What gives? Anyone?
djot
Forum Contributor
Posts: 313
Joined: Wed Jan 14, 2004 10:21 am
Location: planet earth
Contact:

Post by djot »

-
Hi,

Does e.g. $test = "test"; in the inlcude file output (echo $test;) correctly in the other file?

Do you use the predefined variables inside functions or classes?

djot
-
burstgoof
Forum Newbie
Posts: 2
Joined: Thu Nov 18, 2004 10:25 am

Post by burstgoof »

it seems that the statement

" When a file is included, the code it contains inherits the variable scope of the line on which the include occurs. Any variables available at that line in the calling file will be available within the called file, from that point forward."

in the PHP manual for the include function means variables, not user defined constants. in order for that to work the constants have to be defined for the included file as well.

or at least, that's how I got it to work.
Post Reply