Link to home
Start Free TrialLog in
Avatar of phillystyle123
phillystyle123Flag for United States of America

asked on

Default php variable

I'm calling an include at the very top of my code:

includes/page_top.php

i've got this line of code in includes/page_top.php:

<?php if ($crumb2=="wirtzer") echo "Active";?>

now, in the code of the page that is calling includes/page_top.php, i'm defining the crumb2 variable: i.e.:

<?php $crumb2="wirtzer";?>

my issue is that i'm getting server errors (not on the php page but in the log files) like this one:


[Sat Feb 05 10:03:06 2011] [client 76.168.200.119] PHP Notice:  Undefined variable: crumb2 in /home/derm/includes/submenu-forms.php on line 3

i'm guessing this is because includes/page_top.php loads before the rest of the code containing the actual crumb2 variable definition. can i define a default crumb2 variable in includes/page_top.php? so i don't keep getting these errors?




Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

The definition needs to come before the 'include' or at least before the 'if'.  You can define and re-define it wherever you want.  It just has to be defined when you try to use it like in the 'if' statement.
ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of phillystyle123

ASKER

thank you!