#23110 [Opn]: Ugly behaviour of == (and ===)

From: Date: Tue, 08 Apr 2003 11:57:39 +0000
Subject: #23110 [Opn]: Ugly behaviour of == (and ===)
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-37344@lists.php.net to get a copy of this message
ID: 23110 User updated by: kyrael at web dot de Reported By: kyrael at web dot de Status: Open Bug Type: Feature/Change Request Operating System: Linux PHP Version: 4.3.1 New Comment: Btw, in switch you can't use strcmp or ===, because switch seems to use ==. Previous Comments: ------------------------------------------------------------------------ [2003-04-08 06:43:46] kyrael at web dot de <?php list($var1,$var2)=array("1e1","10"); var_dump($var1);var_dump($var2); var_dump($var1==$var2); var_dump($var1===$var2); ?> string(3) "1e1" string(2) "10" bool(true) bool(false) This behaviour is ugly - both operands are strings, and they are clearly not equal. '1e0' and '1.0' and '1' are "equal" too. Same with '3.20' and '3.2'. Does PHP think i am stupid and unable to type numbers when i want them? According to the manual, == returns true if the two operands are equal, and === returns true if the operands are equal and of the same type. == says they are equal, and according to var_dump they are both strings - why doesn't === return true then? So this behaviour is neither logical nor documented. String comparison, even with == when both operands are strings, should return 'equal' if and only if the strings are really equal. Wouldn't be PHP5 a chance to change this? ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=23110&edit=1

« previous php.bugs (#37344) next »