predefined variable scope

From: Date: Mon, 26 Jun 2000 20:57:20 +0000
Subject: predefined variable scope
Groups: php.general 
Request: Send a blank email to php-general+get-3202@lists.php.net to get a copy of this message
Sean, I did almost exactly the same thing. In my case, I use a function in an included file to check for errors whenever I do a database query. I wanted it to e-mail me if an error occured. I also queried the mailing list like you and eventually wound up with this. I'd be interested in any improvements/suggestions: ------------ part of included file ------------------ function checkerrors($db, $action) { if (mysql_errno() != 0) { while (list($var,$value) = each ($GLOBALS)) { $envirs .= "\n$var => $value"; } $errmsg= "The $db could not be $action. There was error # " . mysql_errno(). ": " . mysql_error() . $envirs; mail("me@mymail.com", "mydomain DB error", "$errmsg"); echo "DB error"; die; } else { if ($action == "updated") { echo "<P>Thank you! Your $db information has been updated.\n</P>"; } return true; } } ----------- end of included file ------------------- The checkerrors() function is called by sending it the name of the db I'm working with and the type of action I'm performing. For example a SELECT query would have: checkerrors("database name", "obtained"); kind regards, bill --------------------- you wrote --------------- I'm having an issue with variable scope that I'm not able to find in the docs (which probably just means I'm looking in the wrong place). I have a file with all of my standard stuff in it (colors, email addresses, etc.) called "std-defines.inc." All of the pages on my site 'require()' it. In std-defines.inc, I have defined a function exit_with_errors(). I call this function anywhere in the page that I run into a problem. It prints out formatted error text and does some basic cleanup. I recently added a bit to send email to me whenever the function is called (it should be a rare occurrence). I hoped to have it include basic info about the request (QUERY_STRING, HTTP_REFERER, SCRIPT_NAME, etc.) in the email. But these variables seem to be undefined in exit_with_errors(). Since I can successfully print them directly from the source file, I assume this is an problem with the scope of those variables. Is there some way that I can make those predefined variables available to functions in my .inc files without just passing them as function arguments? Thanks. sean

« previous php.general (#3202) next »