Quote:
quote:
Rich, I don't think it's a good idea to echo ANYTHING out to the client within a wrapper function. You should set an error, or call a debug logging function that handles debug output. This debug function lets you, surprise surprise, wrap how debug statements are handled... you can swap in a function body that suppresses these output messages, only outputs them if a certain user (or user type) is logged in, write these messages to file, email them to an administrator, etc...
|
Nikolai.. let's not break my balls here.
OK, in the wrapper functions that I have designed and used personally, I DON'T echo anything directly to the client and I do exactly that. This is why I suggested using a constant to toggle error reporting. I *assumed* that sami was intelligent enough to heed my warnings about error output and take the idea a step further to include some sort of scheme to prevent the average user from seeing any error output, to write that output to a log, or do whatever with it...
Here is a modified version which does this:
So here we have the creation of a constant... my applications flow through one central file so in my case I only need to set this once at the top of the hierarchy. You can also use a .htaccess file, as I suggested in my last post, to set the error_reporting directive of php.ini, and turn it off or change it to log errors, as well as use a PHP function to determine whether *that* value is on/off and have your custom error reporting toggle based on
its value. An example would be this:
if (ini_get('display_errors') == 1)
{
// display errors...
}
But that all depends on whether your ISP even allows that. Most do.
define("ERROR_BOOLEAN", true);
function query($query, $link = $GLOBALS["link"], $line = null, $file = null, $js_alert = false)
{
$result = mysql_query($query, $link);
if (empty($result))
{
$error = mysql_error().": ";
$error .= mysql_errno()."\n";
$error .= $query."\n";
if (!empty($line)) $error .= "@ Line: $line";
if (!empty($file)) $error .= " in File: $file\n\n";
error($error, $js_alert);
}
return $result;
}
Personally I take all that error garbage in the middle there and put it through a custom error function which checks the value of the constant has options for file logging, formatting for the screen and/or a Javascript alert via window.attachEvent.
function error($error, $js_alert = false)
{
# If error reporting is enabled or the user is admin output the error
if (ERROR_BOOLEAN == true || $_SESSION["user_id"] == 1)
{
if ($js_alert == false)
echo "<div style='color: red'>".nl2br($error)."</div>";
else
echo "<script type='text/javascript'>window.attachEvent('onload', alert('$error'));</script>";
}
else
{
# do a plain text log here, or log into a database table
}
}
And there you have it. The Cadillac of query wrapper functions, IMHO. Well even that can be expanded upon. You can design levels of error severity, write the program to email you if a certain severity level has been reached. Debugging never ends.
Quote:
quote:
if (!function_exists('version_compare') ||
version_compare(php_version(), '4.1.0', '<'))
{
// version is pre-4.1.0, copy into fake superglobals...
}
|
Thanks for pointing this out. The idea that I got came from the user-contributed notes for the predefined variables page.
: )
Rich
:::::::::::::::::::::::::::::::::
Smiling Souls
http://www.smilingsouls.net
:::::::::::::::::::::::::::::::::