#30399 [Opn]: "Comparing strings" manual page

From: Date: Tue, 12 Oct 2004 08:16:00 +0000
Subject: #30399 [Opn]: "Comparing strings" manual page
References: 1  Groups: php.doc 
Request: Send a blank email to phpdoc+get-969364510@lists.php.net to get a copy of this message
ID: 30399 Updated by: vrana@php.net Reported By: techtonik@php.net Status: Open Bug Type: Documentation problem PHP Version: 4.3.9 New Comment: "Is === operator equal to strcmp() if two arguments are strings with numbers in the beginning?" They are equivalent AFAIK. "Many coders use "==" instead of "strcmp" and there should be warning somewhere in manual about possible problems that could arise due to such misuse." There is "If you compare an integer with a string, the string is converted to a number. If you compare two numerical strings, they are compared as integers. These rules also apply to the switch statement." in language.operators.comparison. I think this bug can be marked as bogus. Previous Comments: ------------------------------------------------------------------------ [2004-10-11 17:40:57] techtonik@php.net Description: ------------ After studying some string issues I think we need one more page in manual about strings comparison with a link to/from strcmp. Few confusing examples from user-notes on http://www.php.net/manual/en/language.types.string.php And I haven't found any clear answer about is === operator equal to strcmp() if two arguments are strings with numbers in the beginning? Many coders use "==" instead of "strcmp" and there should be warning somewhere in manual about possible problems that could arise due to such misuse. See also: http://bugs.php.net/bug.php?id=28200 Reproduce code: --------------- <?php $x1 = '111111111111111111'; $x2 = '111111111111111112'; echo ($x1 == $x2) ? "true\n" : "false\n"; //true ?> <? $hello='hi there'; echo($hello?'true':'false'); //true echo($hello==0?'true':'false'); //true!!!!! echo($hello===0?'true':'false'); //false ?> ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=30399&edit=1

« previous php.doc (#969364510) next »