php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #39904 string -> boolean conversion of "\0" should give FALSE
Submitted: 2006-12-20 14:46 UTC Modified: 2014-10-12 14:30 UTC
Votes:1
Avg. Score:2.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:0 (0.0%)
From: zizka at seznam dot cz Assigned:
Status: Wont fix Package: Scripting Engine problem
PHP Version: * OS: *
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 this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: zizka at seznam dot cz
New email:
PHP Version: OS:

 

 [2006-12-20 14:46 UTC] zizka at seznam dot cz
Description:
------------
It might be useful that (boolean)"\0" would give FALSE.
E.g. MySQL's BIT(1) column type can be used to store boolean values, but now PHP converts whatever value to TRUE.

Reproduce code:
---------------
header('Content-Type: text/plain');

echo "\nfalse: ".ord(false);
echo "\ntrue: ".ord(true);
echo "\n\\0: ".(boolean)("\0");
echo "\n\\1: ".(boolean)("\1");

// ord() is here just for thoughts context...

Expected result:
----------------
false: 0
true: 49
\0: 0
\1: 1

Actual result:
--------------
false: 0
true: 49
\0: 1  <----- HERE
\1: 1

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-04-18 19:11 UTC] dave at ifox dot com
To correct, "\0" -> FALSE has not found itself into PHP, but "0" has, and that feature should be reversed.  It's not logical to assume the numerical value of alphanumeric strings in place of the programmer doing so with a numerical cast.

A bug report was even submitted that a string "false" should evaluate to FALSE when converted to boolean.  That won't happen, because PHP developers already know they made a mistake with the "0" hack.  Hopefully in a major version release it will be reversed and all non-empty strings will evaluate to TRUE.

Just like every other loosely-typed language on the planet.
 [2011-01-02 02:13 UTC] jani@php.net
-Summary: string -> boolean conversion of "\0" could give FALSE +Summary: string -> boolean conversion of "\0" should give FALSE -Package: Feature/Change Request +Package: Scripting Engine problem -Operating System: +Operating System: * -PHP Version: 5.2.0 +PHP Version: *
 [2014-10-12 14:30 UTC] nikic@php.net
-Status: Open +Status: Wont fix
 [2014-10-12 14:30 UTC] nikic@php.net
From the experience of treating "0" as false (which is a PITA in many cases), also treating "\0" as false won't happen.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 12:01:27 2024 UTC