php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #18411 print_r(FALSE) not consistant with print_r(TRUE)
Submitted: 2002-07-18 09:09 UTC Modified: 2002-10-31 11:48 UTC
From: peter dot farr at eds dot com Assigned:
Status: Not a bug Package: Documentation problem
PHP Version: 4.2.1 OS: W2K Professional
Private report: No CVE-ID: None
 [2002-07-18 09:09 UTC] peter dot farr at eds dot com
No doubt there is a reason for:

print_r(TRUE)        displays 1
print_r(FALSE)       displays nothing

But too me, it just seems inconsistant, bad practise and very confusing.

I can find nothing in the documentation I have on, why it is like this, as the text indicates 0 is to FALSE as 1 is to TRUE.

It is also obvious from your bug list, that the area of TRUE/FALSE and 1/0 has its problems.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-07-18 09:27 UTC] derick@php.net
This is expected behavior, but I can not find this in the manual either (atleast not on http://www.php.net/manual/en/language.types.boolean.php).
Making it a documentation problem.

Derick
 [2002-07-18 09:39 UTC] goba@php.net
As the boolean page holds information on converting to boolean, I have expected this info to be found on the strings page, but it's not there ;) Though the integer page has info on converting to integer... So this should be explained on the strings page IMHO.
 [2002-10-05 10:27 UTC] rasmus@php.net
TRUE has always been 1 and FALSE "".  To me it would be inconsistent if you did strlen(FALSE) and got TRUE, for example.  It just needs to be documented better.
 [2002-10-31 11:48 UTC] iliaa@php.net
Please do not submit the same bug more than once. An existing
bug report already describes this very problem. Even if you feel
that your issue is somewhat different, the resolution is likely
to be the same. Because of this, we hope you add your comments
to the original bug instead.

Thank you for your interest in PHP.

Dupe of #19575. Even though this is an earlier report I am making it the 'bogus' one, since the 19575 is assigned to Goba and hopefuly will be fixed soon.
 [2015-08-01 16:07 UTC] rasmus at mindplay dot dk
I don't get it, how is this expected behavior?

According to the documentation, print_r() "prints human-readable information about a variable" - as such, I can understand why for example strings aren't quoted, meaning you can't tell the difference between the string "1" and the numeric value 1.

But from the comments, it sounds like your concerns are about the ability to convert back and forth, rather than producing human-readable output? That's not what print_r() is for - we have var_export() for that.

In order to be "human-readable", the following:

    print_r(array(true, false, null));

Should output:

    Array
    (
        [0] => TRUE
        [1] => FALSE
        [2] => NULL
    )

And not:

    Array
    (
        [0] => 1
        [1] =>
        [2] =>
    )
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Thu Sep 19 14:01:29 2019 UTC