Req: Check my coding for best practices
| From: | ajvincent at hotmail dot com | Date: | Fri, 03 Aug 2001 20:22:34 +0000 |
| Subject: | Req: Check my coding for best practices | ||
| Groups: | php.pear.general | ||
| Request: | Send a blank email to pear-general+get-267@lists.php.net to get a copy of this message | ||
I've written a PHP-based function for logging the variables which a
script receives and the source code of the script. (If you want to know
why, well, I wanted to capture certain PHP scripts I execute which
modify the design of my DB.) But, me being a major promoter of
standards, I want to ensure I wrote the code well and in compliance with
the PHP PEAR standards.
Would someone care to tell me (a) what I need to do to bring this up to
PEAR standards, and (b) what I can do to tweak this function and make it
stronger? The idea is I use include()to attach this script to the
script I wish to make a log record of.
Alex Vincent
author, JavaScript Laboratory (work in progress)
<?php
function logCall()
{
global $PATH_TRANSLATED, $HTTP_POST_VARS, $HTTP_GET_VARS, $HTTP_COOKIE_VARS, $DOCUMENT_ROOT,
$logCall_disabled;
if (!$logCall_disabled) {
$uber_array=array_merge($HTTP_POST_VARS,$HTTP_GET_VARS,$HTTP_COOKIE_VARS);
$logFile = fopen($DOCUMENT_ROOT . "/logphp.txt", "a");
fwrite($logFile, "<?php\n");
fwrite($logFile, "// " . date("r") . "\n\n");
while (list($key,$var)=each($uber_array)) {
if (is_array($var)) {
while(list($akey,$avar)=each($var)) {
$str
.="\$".$key."[".$akey."]=\"".$avar."\";\n";
}
fwrite($logFile,"$str");$str="";
}else{
fwrite($logFile,"\$$key=\"$var\";\n");
}
}
fwrite($logFile, "$"."logCall_disabled = TRUE;\n");
fwrite($logFile, "?".">\n");
$self = fopen($PATH_TRANSLATED,"r");
fwrite($logFile, fread($self, filesize($PATH_TRANSLATED)));
fclose($logFile);
}
}
logCall()
?>