Bug #66211 [NEW]: integer/string comparisons have bad type-casting
| From: | php at charles-chandler dot org | Date: | Sun, 01 Dec 2013 02:14:52 +0000 |
| Subject: | Bug #66211 [NEW]: integer/string comparisons have bad type-casting | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-183035@lists.php.net to get a copy of this message | ||
From: php at charles-chandler dot org
Operating system: Mac OSX
PHP version: 5.4.22
Package: Variables related
Bug Type: Bug
Bug description:integer/string comparisons have bad type-casting
Description:
------------
---
From manual page: http://www.php.net/types.comparisons
---
2 == '2b'
I understand why, in a loosely typed language, 2 == '2', but it doesn't
make sense for an integer to be equal-equal to a string that simply
begins with an integer, such as 2 == '2b', so this looks like a bug to
me. Rather than casting the string to an integer (i.e., intval('2b') ==
2), the integer should cast to a string for the comparison (i.e.,
strval(2) != '2b').
Tested in PHP 5.2.5 and 5.3.13.
Test script:
---------------
<?php
// this is the problem, which we'd expect
// to return false, but which returns true:
echo (2 == '2b').'<br />';
// this is probably what's happening:
echo (2 == intval('2b')).'<br />';
// this is what probably should happen:
echo (strval(2) != '2b').'<br />';
?>
--
Edit bug report at https://bugs.php.net/bug.php?id=66211&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=66211&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=66211&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=66211&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=66211&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=66211&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=66211&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=66211&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=66211&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=66211&r=support
Expected behavior: https://bugs.php.net/fix.php?id=66211&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=66211&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=66211&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=66211&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=66211&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=66211&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=66211&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=66211&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=66211&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=66211&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=66211&r=mysqlcfg