As you know var_dump()
in addition to value show its data type and length.
Is there any way to log its output to
From: http://sixrevisions.com/web-development/how-to-debug-php-using-firefox-with-firephp/
Fb::log($array, "dumping an array")
That will get you the type and data. You'll have to do extra logging manually for length/count.
You can dump JavaScript to the console by putting a console.log() in a script tag:
<script type="text/javascript">
console.log("hello");
</script>
So if you do a php dump in there...
<script type="text/javascript">
console.log("<?php var_dump('abc'); ?>");
</script>
You just need to be careful about ' and " in the var_dump breaking your JavaScript. In this example it will be ok because the HTML would be:
<script type="text/javascript">
console.log("string 'abc' (length=3)");
</script>
Just remember the php is processed then put in the JavaScript. You could also dump it to a comment:
<!--
<?php
var_dump('abc');
?>
-->
Then you can view source, or inspect element.
<script>console.log( <?= json_encode( $var ) ?> )</script>
Just throwing my hat in the ring. It sounds like FirePHP is the best way to go.
if you just want to see the var_dump
out put in the firebug (client side) without doing any things in Javascript I would recommande using cookies following is an illustration how you can perform it that way:
<?php
$str = "Abu Romaïssae";
sendVarDumpToFront($str);
echo "<pre>";
echo $str."\n";
function sendVarDumpToFront( $mixed ){
ob_start();
var_dump($mixed);
$content = ob_get_contents();
ob_end_clean();
setcookie("var_dump",$content);
}
than you can have it in firebug this way:
IMPORTANT
since this way uses cookies you will have to put the var_dump content before outputing any content otherwise this will not work
FirePHP does the job well + you can use it while you're developing Ajax.
Sample code:
require_once('FirePHPCore/fb.php'); # add the library
fb($var); #log the variable
fb( var_export($var,true) ); # log the variable with the var_export format
If you're passing an array to it, you can click it from your console and it will open a popup on your screen. You can even expand/collapse arrays and objects.
EDIT:
If you're looking for data types and length, use var_dump()
.
fb( var_dump( array(
1,
'a',
true
) ) );
I think one easy way to achieve this goal is to do a simple
console.log(<?php var_export($var, true) ?>);