Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

A more pretty/informative Var_dump alternative in PHP? [closed]

People also ask

What is Var_dump function in PHP?

The function var_dump() displays structured information (type and value) about one or more expressions/variables. Arrays and objects are explored recursively with values indented to show structure. All public, private and protected properties of objects will be returned in the output.

Which is true about Var_dump () function?

4. Which is true about var_dump() function? Explanation: var_dump() cuts off loop after getting the same element three times is true about var_dump() function.

What is the difference between Print_r and Var_dump in PHP?

var_dump() displays values along with data types as output. print_r() displays only value as output. It does not have any return type. It will return a value that is in string format.

What is Var_dump in PHP w3schools?

The var_dump() function dumps information about one or more variables. The information holds type and value of the variable(s).


A full year of time and labor after asking this, I've finally open sourced my version of var_dump, Kint. Read about it in the project page, or directly in github.

Here's a screenshot:

kint

Sorry for the plug :)


EDIT: I'd just like to remind the commenters, that this is not a support forum, if you're having problems/want a feature, please file an issue. Support requesting comments will be flagged for deletion.


My prefered on is the var_dump function, as provided by the Xdebug extension : just install the extension (easy, both on windows and Linux), and var_dump gets a better output :

  • better formating
    • HTML
    • colors
  • and you have options to tune how much informations should be displayed

And a quick screenshot :

xdebug


And, of course, Xdebug brings loads of other usefull stuff, like remote debugging (i.e. graphical debugging of your PHP application, in Eclipse PDT for instance), profiling, ...


I wrote my own: REF (demo):

r() output

Plans are to add text-only rendering, and display info about the input expression like Kint does...


Here's mine, which I use inline, very useful:

$pretty = function($v='',$c="&nbsp;&nbsp;&nbsp;&nbsp;",$in=-1,$k=null)use(&$pretty){$r='';if(in_array(gettype($v),array('object','array'))){$r.=($in!=-1?str_repeat($c,$in):'').(is_null($k)?'':"$k: ").'<br>';foreach($v as $sk=>$vl){$r.=$pretty($vl,$c,$in+1,$sk).'<br>';}}else{$r.=($in!=-1?str_repeat($c,$in):'').(is_null($k)?'':"$k: ").(is_null($v)?'&lt;NULL&gt;':"<strong>$v</strong>");}return$r;};

echo $pretty($some_variable);

You are looking for Krumo (Warning, Chrome alerts for Malware).

To put it simply, Krumo is a replacement for print_r() and var_dump(). By definition Krumo is a debugging tool (initially for PHP4/PHP5, now for PHP5 only), which displays structured information about any PHP variable.