DebuggingForCookbookAuthors-Talk

Summary: Talk page for DebuggingForCookbookAuthors.
Maintainer: XES
Users: (View / Edit)

This space is for User-contributed commentary and notes. Please include your name and a date along with your comment.

Comments


I liked the use of (:message:) for debugging, and have enhanced the handy debug message function to cover more eventualities, viz:

// Debug function
function smsg($smsgprefix, $smsgtxt, $switch=0) { 
# see https://pmwiki.org/wiki/Cookbook/DebuggingForCookbookAuthors
# add debug text to message array
	global $MessagesFmt;
    $MessagesFmt [] = '<smaller style="font-family:monospace"><i>' . $smsgprefix . '</i>: ';
    switch (true) {
        case (is_null($smsgtxt)) : 
            $MessagesFmt [] .= 'null'; 
            break;
        case (is_bool($smsgtxt)) : 
            $MessagesFmt [] .= var_export($smsgtxt,true); 
            break;
        case ($switch == true || is_array($smsgtxt)) :
            array_walk_recursive ($smsgtxt, 'sanitise');
		    $MessagesFmt[] .= "<pre>\n" . print_r($smsgtxt, true) . "</pre>\n"; 
            break;
	default: 
            $MessagesFmt[] .= htmlspecialchars($smsgtxt, ENT_NOQUOTES); 
            break;
    }
    $MessagesFmt[] .= "</smaller><br />\n";
} # end smsg
##
function sanitise(&$item, $itemkey) {
# escape html special characters   
    if (is_string($item)) $item = htmlspecialchars($item, ENT_NOQUOTES); 
} # end sanitise    
simon June 07, 2020, at 08:20 AM

Talk page for the DebuggingForCookbookAuthors recipe (users).