kath — 2012-10-09T09:20:53-04:00 — #1
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.
aarbrown — 2012-10-09T10:45:11-04:00 — #2
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)
cups — 2012-10-09T10:46:25-04:00 — #3
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'.
system — 2014-10-07T23:01:25-04:00 — #4
This topic is now closed. New replies are no longer allowed.