ID: 25734 Updated by: [EMAIL PROTECTED] Reported By: rbotzer at yahoo dot com -Status: Open +Status: Bogus Bug Type: Feature/Change Request Operating System: MacOS X PHP Version: 4.3.3 New Comment:
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; } } Previous Comments: ------------------------------------------------------------------------ [2003-10-02 15:46:23] rbotzer at yahoo dot com First, backwards compatability actually will still be maintained. An extended list of FALSE type-casts will support the subset of previous versions. For example, if a new String function is added in 4.3.4, that doesn't mean that 4.3.4 doesn't support the subset of String functions from 4.3.3. Therefore, code that was developed before will not depend on the new type-casting, and backwards compatability will be maintained. Second, I am not talking about the noun 'false', so comparisons to 'nyet' aren't relevant. I'm talking about type casting the string 'false' to the boolean FALSE. Let's not claim that PHP is strongly typed, since it isn't. Due to the fact that it is a loosely typed scripting language, the scenario should make sense: assume isValidUser is an RPC that uses SOAP and recieves strings "false" or "true" - where these are actually boolean values. Then the line: if ((boolean) $this->isValidUser()) should not evaluate to true if the method returned "false". It should cast into FALSE. I'm just suggesting a common sense thing here - treating (boolean)"false" as the boolean value FALSE. I'm not talking about all the nouns for 'false' in all languages. Consider that (boolean)0 === FALSE is just as arbitrary, and much less clear than (boolean)"false" being FALSE rather than TRUE. ------------------------------------------------------------------------ [2003-10-02 13:08:55] [EMAIL PROTECTED] Bad idea - think about backwards compatibility. And what would be next? Should "no", "off", "nyet", "falsch" and a bunch of other strings also evaluate to false? ------------------------------------------------------------------------ [2003-10-02 12:57:52] 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) ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=25734&edit=1