Req #39904 [Opn->Wfx]: string -> boolean conversion of "\0" should give FALSE
Edit report at https://bugs.php.net/bug.php?id=39904&edit=1
ID: 39904
Updated by: nikic@php.net
Reported by: zizka at seznam dot cz
Summary: string -> boolean conversion of "\0" should give
FALSE
-Status: Open
+Status: Wont fix
Type: Feature/Change Request
Package: Scripting Engine problem
Operating System: *
PHP Version: *
Block user comment: N
Private report: N
New Comment:
From the experience of treating "0" as false (which is a PITA in many cases), also
treating "\0" as false won't happen.
Previous Comments:
------------------------------------------------------------------------
[2009-04-18 19:11:56] 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.
------------------------------------------------------------------------
[2006-12-20 14:46:44] 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
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=39904&edit=1
Thread (4 messages)