ID: 39904
Comment by: dave at ifox dot com
Reported By: zizka at seznam dot cz
Status: Open
Bug Type: Feature/Change Request
PHP Version: 5.2.0
New Comment:
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.
Previous Comments:
------------------------------------------------------------------------
[2009-04-17 23:56:47] dave at ifox dot com
This is by far the worst thing that has found itself into PHP.
------------------------------------------------------------------------
[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 http://bugs.php.net/?id=39904&edit=1