print_r outputs nothing for "false"

php.internals

Jakob Buchgraber

19 years ago
Hello! While debuging I recognized that print_r does not output anything for bool(false) (PHP 5.2.1). e.g. <?php print_r (array (true, false, "String")); ?> Expected result: Array ( [0] => 1 [1] => 0 [2] => String ) Actual result: Array ( [0] => 1 [1] => [2] => String ) I was not quite sure whether this is expected behavior, so I haven't opened a bug yet. So, is it expected and why? Cheers, Jay

Rasmus Lerdorf

19 years ago
Jakob Buchgraber wrote:
> Hello! > > While debuging I recognized that print_r does not output anything for > bool(false) (PHP 5.2.1). > > e.g. > <?php > print_r (array (true, false, "String")); > ?> > > Expected result: > Array > ( > [0] => 1 > [1] => 0 > [2] => String > ) > > Actual result: > Array > ( > [0] => 1 > [1] => > [2] => String > ) > > > I was not quite sure whether this is expected behavior, so I haven't > opened a bug yet. > > So, is it expected and why?
Because false is not 0. 0 evaluates to false, but so do many other things. -Rasmus

Robert Deaton

19 years ago
http://www.php.net/manual/en/language.types.string.php#language.types.string.casting
-- --Robert Deaton

Stefan Walk

19 years ago
Hi, for debugging i'd use var_dump, which doesn't output ambiguous things. Regards, Stefan