#26821 [Opn->Bgs]: if("NANC" < 0) - always evaluates TRUE

From: Date: Fri, 09 Jan 2004 16:04:30 +0000
Subject: #26821 [Opn->Bgs]: if("NANC" < 0) - always evaluates TRUE
References: 1  Groups: php.doc 
Request: Send a blank email to phpdoc+get-969358047@lists.php.net to get a copy of this message
ID: 26821 Updated by: sp@php.net Reported By: ivo at benetech dot org -Status: Open +Status: Bogus Bug Type: Documentation problem Operating System: Linux / RH 7.3 PHP Version: 4.3.4 New Comment: Who wants to evaluate "NANC" < 0??? It _absolutely_ makes no sense. If someone asks you if A+B > 4 is, you wouldn't know what to calculate... FYI I've tried ivo's script. Under PHP 4.3.3 it produces "should happen...but doesnt" and under 4.3.0 it's "should not happen...but does". Previous Comments: ------------------------------------------------------------------------ [2004-01-08 22:35:09] skissane at ics dot mq dot edu dot au Vrana: your comment makes no sense. If "NANC" is converted to 0, then 0 < 0 would be FALSE, not true. Compare these expressions: "NANC" < 0 result TRUE "NANC" < "0" result FALSE 0 < 0 result FALSE So it seems it is neither converting "NANC" to an integer 0, nor 0 to a string "0". What actually is going on? The documentation should clarify this. ------------------------------------------------------------------------ [2004-01-07 13:20:58] ivo at benetech dot org It also print 0 as expected. if( (int) "NANC" < 0) also evaluates as expected. ------------------------------------------------------------------------ [2004-01-07 05:53:18] vrana@php.net "NANC" is converted to 0 for comparison. It works for me as expected. What is printed by the code <?php echo intval("NANC"); ?> on your system? ------------------------------------------------------------------------ [2004-01-06 18:08:12] ivo at benetech dot org Documentation needs to be more explicit about php being strongly typed. http://www.php.net/manual/en/language.types.type-juggling.php or http://www.php.net/manual/en/language.types.string.php#language.types.string.conversion ------------------------------------------------------------------------ [2004-01-06 17:23:58] sniper@php.net RTFM: http://www.php.net/manual/en/types.comparisons.php (never ever compare different types like that) ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at http://bugs.php.net/26821 -- Edit this bug report at http://bugs.php.net/?id=26821&edit=1

« previous php.doc (#969358047) next »