ID: 17698 Comment by: simon at esoft dot dk Reported By: manderson at dsrglobal dot com Status: Bogus Bug Type: Strings related PHP Version: 4.1.2 New Comment:
I do believe this is a bug nevertheless! When you specificly typecast a value to a certain type you expect it to be compared without being cast back to Integer afterwards. Quote from the PHP manual about "Strings" "You can convert a value to a string using the (string) cast, or the strval() function. String conversion is automatically done in the scope of an expression for you where a string is needed. This happens when you use the echo() or print() functions, or when you compare a variable value to a string." I like to point out the last line, "when you compare a variable to a string", this is exactly what you do, so the fact is that comparing to a constant string would work but not a variable? This makes no sense. Previous Comments: ------------------------------------------------------------------------ [2002-06-11 10:00:33] manderson at dsrglobal dot com corrected "From" email address ------------------------------------------------------------------------ [2002-06-11 09:57:15] manderson at dsrglobal dot com What is the purpose of "(string)"? ------------------------------------------------------------------------ [2002-06-11 09:46:23] [EMAIL PROTECTED] 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. ------------------------------------------------------------------------ [2002-06-11 09:41:00] manderson at dsrglobal dot com 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