Hi y'all, I'm making a page with a lot of php includes. Everything works fine, but when I look at the server error log I'm getting a lot of messages complaining that variables are not defined. Again, everything's working, so the variables are defined, just not in the php includes. I can get around it by using if(isset(variable)), but I was just wondering what would cause this? Do I need to declare the variables as global in order to make the server happy if I'm using them in php includes? Thanks for helping me to understand. Rob
The variables that are being used already are declared correct? As in maybe its the order of the includes you are having an issue wiht? include file with vars include file that uses vars and not the other way around.
Well, obviously they're not all declared otherwise you wouldn't get those errors. Everything may still appear to be working though depending on what the value of those variables is supposed to be. If it's just supposed to be $bla = false; then everything will still work because an undefined variable will also match this if ($bla) {}
$query = "SELECT * FROM tbl WHERE code like '" . $code . "'"; $result = mysql_query($query) or die(mysql_error()); $row = mysql_fetch_array($result); $var_name = $row[1]; // $var_name declared include called inside php include: echo $var_name; // gives error 'undefined variable' even though $var_name echoes to the page properly This is just one example. There is html outside of the php in the calling file and the include, and there are several includes on the page, some of which may use the variable before this include. Is that the problem?
You are not showing all the code: include called inside php include: Code (markup): Do not show us "concept code", show the real deal.
That's not concept code. That is the actual code minus a couple of variables pulled from the array, and that is the actual code in the include. Also, I changed the variable name, but still, all in all, that's it.
If just about everything I have is an include, and the variable is used by a prior include (but not modified), can that cause this problem?