#31380 [NEW]: PHP logic problem
| From: | alex at arjomand dot net | Date: | Sun, 02 Jan 2005 22:28:16 +0000 |
| Subject: | #31380 [NEW]: PHP logic problem | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-71395@lists.php.net to get a copy of this message | ||
From: alex at arjomand dot net
Operating system: Windows XP Pro
PHP version: 4.3.10
PHP Bug Type: *General Issues
Bug description: PHP logic problem
Description:
------------
There is a problem with PHP's logic and string conventions. Currently, the
comparison 0 == "alex" (or any arbitrary string) returns true. The
comparison 0 == false also returns true, but the comparison "alex" ==
false returns false. This gives us the following logical fallacy:
A == B,
B == C,
but A != C.
The first comparison (0 == 'alex') is due to a PHP convention explained
here:
http://ca.php.net/manual/en/language.types.string.php#language.types.string.conversion
The third comparison ("alex" == false) is due to an implicit PHP
convention - that any non-empty string is true.
These two conventions are inconsistent, and lead to the above errors.
Under this system, PHP no longer has referential integrity.
Reproduce code:
---------------
<?
echo (0 == false) === true; # returns true
echo "<br>";
echo (0 == "alex") === true; # returns true
echo "<br>";
echo ("alex" == false) === false; # returns false
?>
--
Edit bug report at http://bugs.php.net/?id=31380&edit=1
--
Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=31380&r=trysnapshot4
Try a CVS snapshot (php5.0): http://bugs.php.net/fix.php?id=31380&r=trysnapshot50
Try a CVS snapshot (php5.1): http://bugs.php.net/fix.php?id=31380&r=trysnapshot51
Fixed in CVS: http://bugs.php.net/fix.php?id=31380&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=31380&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=31380&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=31380&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=31380&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=31380&r=support
Expected behavior: http://bugs.php.net/fix.php?id=31380&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=31380&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=31380&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=31380&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=31380&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=31380&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=31380&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=31380&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=31380&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=31380&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=31380&r=mysqlcfg