Bug #65570 [NEW]: 0 equals any string
| From: | l dot werner at sprengnetter dot de | Date: | Wed, 28 Aug 2013 09:15:38 +0000 |
| Subject: | Bug #65570 [NEW]: 0 equals any string | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-181260@lists.php.net to get a copy of this message | ||
From: l dot werner at sprengnetter dot de
Operating system: Linux
PHP version: 5.5.3
Package: *General Issues
Bug Type: Bug
Bug description:0 equals any string
Description:
------------
When matching any string against 0 with == or != PHP will say they match.
This is in my eyes absolutely wrong because testing against other types
will not result in this behavior.
Test script:
---------------
<?php
echo "null != 'string' -> ";
var_dump(null != 'string');
echo "<br />";
echo "false != 'string' -> ";
var_dump(false != 'string');
echo "<br />";
echo "0 != 'string' -> ";
var_dump(0 != 'string');
echo "<br />";
echo "1 != 'string' -> ";
var_dump(1 != 'string');
Expected result:
----------------
null != 'string' -> bool(true)
false != 'string' -> bool(true)
0 != 'string' -> bool(true)
1 != 'string' -> bool(true)
Actual result:
--------------
null != 'string' -> bool(true)
false != 'string' -> bool(true)
0 != 'string' -> bool(false)
1 != 'string' -> bool(true)
--
Edit bug report at https://bugs.php.net/bug.php?id=65570&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=65570&r=trysnapshot54
Try a snapshot (PHP 5.3): https://bugs.php.net/fix.php?id=65570&r=trysnapshot53
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=65570&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=65570&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=65570&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=65570&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=65570&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=65570&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=65570&r=support
Expected behavior: https://bugs.php.net/fix.php?id=65570&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=65570&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=65570&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=65570&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=65570&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=65570&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=65570&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=65570&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=65570&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=65570&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=65570&r=mysqlcfg