Re: Finer points of debugging: vardump vs. print_r
| From: | Morgan Curley | Date: | Mon, 09 Apr 2001 21:17:40 +0000 |
| Subject: | Re: Finer points of debugging: vardump vs. print_r | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-47884@lists.php.net to get a copy of this message | ||
I generally include the following function:
function dump( $label, $input ){
echo( "<PRE>" );
echo( "<H2>$label</H2>\n" );
print_r( $input );
echo( "</PRE>" );
return 1;
}
or if you like javascript this pops up an alert wherever you insert the dump call in your page
function dump( $label, $input ){
ob_start();
print_r( $input );
$gc = ob_get_contents();
ob_end_clean();
$gc = preg_replace( "/'/", "\\'", $gc );
$gc = preg_replace( '/\n/', '\\n', $gc );
echo( "<script>alert( '$label\\n".$gc."' );</script>" );
return 1;
}
then for simple debugging I call
dump( "My Label", $my_var );
With the javascript you can do some cool things like having divs generated per $label.
morgan
At 02:26 PM 4/9/2001, you wrote:
Just a question that has been besetting me for a while: which is better for debugging -- vardump( ) or print( ) ? Does anyone have a preference? Why? Is one better than the other? Thanks for answering this prickly question! John Lim -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net For additional commands, e-mail: php-general-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net