print_r will not tell you if a variable is NULL, but var_dump will. So I
usually use both.
--
Plutarck
Should be working on something...
...but forgot what it was.
""John Lim"" <heyjo...@yahoo.com> wrote in message
news:9asuq0$f1n$1...@toye.p.sourceforge.net...
> 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...@lists.php.net
> For additional commands, e-mail: php-gene...@lists.php.net
> To contact the list administrators, e-mail: php-lis...@lists.php.net
>
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: php-general...@lists.php.net
For additional commands, e-mail: php-gene...@lists.php.net
To contact the list administrators, e-mail: php-lis...@lists.php.net
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
Descriptions (from manual) :
--------------------------------
print_r -- Prints human-readable information about a variable
(PHP 4)
var_dump -- Dumps information about a variable
(PHP 3 >= 3.0.5, PHP 4)
An example :
--------------------------------
<pre>
<?php
$example = array ('str' => 'is good',
'letters' => array ('a','b','c'),
'integer' => 31,
'float/double' => 35.3787,
24 => 'hello');
echo 'print_r :'. "\n\n";
print_r ($example);
echo 'var_dump :'. "\n\n";
var_dump ($example);
?>
</pre>
Output (layout altered) :
---------------------------------
print_r :
Array
(
[str] => is good
[letters] => Array
(
[0] => a
[1] => b
[2] => c
)
[integer] => 31
[float/double] => 35.3787
[24] => hello
)
var_dump :
array(4)
{
["str"] => string(7) "is good"
["letters"] => array(3)
{
[0] => string(1) "a"
[1] => string(1) "b"
[2] => string(1) "c"
}
["integer"] => int(31)
["float/double"] => float(35.3787)
[24] => string(5) "hello"
}
Manual Entries :
--------------------------------
http://www.php.net/manual/en/function.print-r.php
http://www.php.net/manual/en/function.var-dump.php
Regards,
Philip
(test: print var dump faq8490)
On Tue, 10 Apr 2001, John Lim 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...@lists.php.net
> For additional commands, e-mail: php-gene...@lists.php.net
> To contact the list administrators, e-mail: php-lis...@lists.php.net
>
Philip Olson
http://www.cornado.com/
You tip is fantastic. Will post it (with your permission) at my weblog,
http://php.weblogs.com/ tomorrow.
Regards, John
"Morgan Curley" <mcu...@e4media.com> wrote in message
news:4.3.2.7.2.200104...@e4media.com...