Re: Finer points of debugging: vardump vs. print_r
| From: | John | Date: | Tue, 10 Apr 2001 06:54:21 +0000 |
| Subject: | Re: Finer points of debugging: vardump vs. print_r | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-47971@lists.php.net to get a copy of this message | ||
Hi Morgan,
You tip is fantastic. Will post it (with your permission) at my weblog,
http://php.weblogs.com/ tomorrow.
Regards, John
"Morgan Curley" <mcurley@e4media.com> wrote in message
news:4.3.2.7.2.20010409161456.01e24f08@e4media.com...
> 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
>