Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which php variable debugging function do you use? var_dump, print_r, var_export, other? [closed]

Tags:

php

debugging

I personally use var_dump, but lots of people like print_r.

What does everyone use? Pros and Cons?

Does someone have a special home brew function of their own?

like image 325
SeanDowney Avatar asked Dec 02 '22 08:12

SeanDowney


2 Answers

I use print_r() because I like the pretty array structure... but var_dump does give you a bit more information (like types)

$obj = (object) array(1, 2, 3);

// output of var_dump:
object(stdClass)#1 (3) {
  [0]=>
  int(1)
  [1]=>
  int(2)
  [2]=>
  int(3)
}

// output of print_r
stdClass Object
(
  [0] => 1
  [1] => 2
  [2] => 3
)    
like image 63
Owen Avatar answered Dec 04 '22 00:12

Owen


I always use the Xdebug extended var_dump. It gives out a lot of verbose output.

See: http://xdebug.org/docs/display for more details.

like image 33
Shoan Avatar answered Dec 04 '22 00:12

Shoan