|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2003-10-02 12:57 UTC] rbotzer at yahoo dot com
Description:
------------
When I type-cast the string "false" into a boolean it evaluates to TRUE. This is non-sensical. Can we please change the type-casting so that it evaluates as FALSE.
Thanks,
Ronen Botzer
Reproduce code:
---------------
<?php
// start example:
$x = "false";
if ($x === "false") {
print ("the string value of x is evaluating as \"false\" \n");
var_dump ($x);
print ("\n");
}
$y = (boolean) $x;
print ("\$x was type-cast into boolean \$y\n\n");
if ($y) {
print ("the boolean value of x is evaluating as true\n");
var_dump ($y);
}
// end example
?>
Expected result:
----------------
I expect to only see a printout from the first conditional. The second should evaluate as false, and not print.
Actual result:
--------------
the string value of x is evaluating as "false"
string(5) "false"
$x was type-cast into boolean $y
the boolean value of x is evaluating as true
bool(true)
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Dec 01 02:00:01 2025 UTC |
This FR will not be done. Accept that. It *IS* BC breaking because some scripts rely on ANY non-zero valued / non-zero length string evaluating to true regardless of textual content. Your isValidUser method should be modified to return proper boolean values rather than text strings. If nothing else, you can write a simple wrapper to satisfy your own personal needs very easily: function my_boolean($val) { if (strtolower(trim($val)) === 'false') { return false; } else { return (boolean)$val; } }