Bug #17698 Updated: explicit casting of string not functioning properly

From: Date: Tue, 11 Jun 2002 13:46:24 +0000
Subject: Bug #17698 Updated: explicit casting of string not functioning properly
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-10108@lists.php.net to get a copy of this message
ID: 17698 Updated by: sander@php.net Reported By: manderson@dsrglobal.net -Status: Open +Status: Bogus Bug Type: Strings related PHP Version: 4.1.2 New Comment: This is not a bug. PHP has no real types and tries to decide which type it is. Use === or !== to check for type too. Previous Comments: ------------------------------------------------------------------------ [2002-06-11 09:41:00] manderson@dsrglobal.net When comparing two strings for equality they appear to be, if possible, being converted to integers prior to the comparison even when explicitly cast. The following script should demonstrate the issue: <?php if("0123" == "123") { echo "\"0123\" == \"123\"<br />\n"; } if("0123" != "123") { echo "\"0123\" != \"123\"<br />\n"; } if((string) "0123" == (string) "123") { echo "(string) \"0123\" == (string) \"123\"<br />\n"; } if((string) "0123" != (string) "123") { echo "(string) \"0123\" != (string) \"123\"<br />\n"; } if(!strcasecmp("0123", "123")) { echo "strcasecmp(\"0123\", \"123\") returns equal<br />\n"; } else { echo "strcasecmp(\"0123\", \"123\") returns not equal<br />\n"; } ?> This script will echo : <output> "0123" == "123" (string) "0123" == (string) "123" strcasecmp("0123", "123") returns not equal </ouput> Obviously "0123" is not the same as "123". <configuration> './configure' '--with-mysql' '--with-xml' '--with-apxs' '--with-config-file-path=/etc/httpd' </configuration> ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=17698&edit=1

« previous php.bugs (#10108) next »