Bug #17698: explicit casting of string not functioning properly

From: Date: Tue, 11 Jun 2002 13:41:00 +0000
Subject: Bug #17698: explicit casting of string not functioning properly
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-10107@lists.php.net to get a copy of this message
From: manderson@dsrglobal.net Operating system: PHP version: 4.1.2 PHP Bug Type: Strings related Bug description: explicit casting of string not functioning properly 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 bug report at http://bugs.php.net/?id=17698&edit=1 -- Fixed in CVS: http://bugs.php.net/fix.php?id=17698&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=17698&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=17698&r=needtrace Try newer version: http://bugs.php.net/fix.php?id=17698&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=17698&r=support Expected behavior: http://bugs.php.net/fix.php?id=17698&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=17698&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=17698&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=17698&r=globals

« previous php.bugs (#10107) next »