Bug #17698 Updated: explicit casting of string not functioning properly
ID: 17698
Updated by: manderson@dsrglobal.com
-Reported By: manderson@dsrglobal.net
+Reported By: manderson@dsrglobal.com
Status: Bogus
Bug Type: Strings related
PHP Version: 4.1.2
New Comment:
corrected "From" email address
Previous Comments:
------------------------------------------------------------------------
[2002-06-11 09:57:15] manderson@dsrglobal.com
What is the purpose of "(string)"?
------------------------------------------------------------------------
[2002-06-11 09:46:23] sander@php.net
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@dsrglobal.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
Thread (5 messages)