php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #29977 bool cast of "0000000000000"
Submitted: 2004-09-04 01:22 UTC Modified: 2005-03-14 09:13 UTC
From: hd dot php at aimail dot de Assigned:
Status: Not a bug Package: Documentation problem
PHP Version: 4.3.10 / 5+ OS: linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: hd dot php at aimail dot de
New email:
PHP Version: OS:

 

 [2004-09-04 01:22 UTC] hd dot php at aimail dot de
Description:
------------
* PHP Version 4.3.4 *

bool cast of "0000000000000" should be false, not true.

A "0000000000000" is returned from mysql timestamp fields.

(bool)"0000000000000"
should be consistent with
(bool)(int)"0000000000000"

At this point it is not.



Reproduce code:
---------------
<?
echo((bool)"0000000000000"?"true":"false");
?>

Expected result:
----------------
false

Actual result:
--------------
true

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-09-05 10:04 UTC] aidan@php.net
"00" is a string, like any other string. The only other string that will evaluate to false is "0".

This may, however, be something we should fix, and at the very least document - what do others think?

TRUE: $ php -r 'var_dump((bool)"00");'
FALSE: $ php -r 'var_dump((bool)"0");'
 [2005-03-13 21:46 UTC] sniper@php.net
Document it.

 [2005-03-14 08:46 UTC] mail at etarion dot de
Well, it is documented. In the type juggling section it is said that the only strings evaluating to false are "" and "0".
 [2005-03-14 09:13 UTC] vrana@php.net
Already documented at http://php.net/language.types.boolean: "When converting to boolean, the following values are considered FALSE: ... the empty string, and the string "0" ... Every other value is considered TRUE."
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sun Jul 06 20:01:35 2025 UTC