I have a php file (oops.php) that calls in "mma-config.php" which contains...
global $sERROR_NO_CONN = "Error connecting to database. Check back later";
global $sERROR_NO_ACCESS = "You are not authorized to access this area.";
global $sERROR_ADD = "An error was encountered adding the record";
global $sERROR_MODIFY = "An error was encountered modifying the record.";
Inside oops.php, I call mma-config.php and want to reference the error message - example:
$SESSION['error'] = ERRORNO_CONN;
However when the oops php page is displayed, instead of the error message, it displays "ERROR_NO_CONN";
I did check in the oops.php page that I called in the mma-config.php script
Can't figure out what the problem is.
Do you have any additional code that you can post? It's hard to determine scoping without seeing the full context.
It looks like you might have the wrong idea about the global keyword from what you have posted though. Using the global keyword when declaring variables should result in a parse error (http://codepad.org/uygSzPAW)
The correct usage of global is like so: http://codepad.org/nMtWxwlF
global should be used withing functions to access variables that are declared in the global scope ($foo in both examples is declared in the global scope)
Not sure if you are getting mixed up with define, or whether you need the global keyword at all in this particular context.
Otherwise just access the var as $sERROR_NO_CONN ie with an 's'.
This topic is now closed. New replies are no longer allowed.