php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #9979 (! $a == $b) and ($a != $b) discreprency
Submitted: 2001-03-25 13:40 UTC Modified: 2001-03-25 18:28 UTC
From: ying at zippydesign dot com Assigned:
Status: Closed Package: Scripting Engine problem
PHP Version: 4.0.4pl1 OS: Linux
Private report: No CVE-ID: None
 [2001-03-25 13:40 UTC] ying at zippydesign dot com
I've noticed a difference in how (! $a == $b) and ($a != $b) behaves between in PHP 4.04pl1.  I think those should be syntactically equivalent, but with PHP 4.04pl1 they are not, whereas with older versions they are.  Here is a script to test this:

<?
$a = "foo";
$b = "bar";

echo "\nTest 1: ";
echo (! $a == $b) ? "true" : "false";

echo "\nTest 2: ";
echo ($a != $b) ? "true" : "false";

echo "\n";
?>

With PHP4.04pl1 the results are:

Test 1: false
Test 2: true

With PHP3.18 the results are:

Test 1: true
Test 2: true

It would seem that the results with PHP 4 are wrong here, please advise.  Information about my system follows:

OS: Redhat Linux
Kernel: 2.4.1
PHP Version: 4.04pl1
'./configure' '--disable-debug' '--with-config-file-path=/usr/local/etc' '--enable-bcmath' '--with-mysql' '--with-pgsql' '--with-gdbm' '--with-openssl' '--with-curl' '--with-readline' '--enable-inline-optimization'

PHP Version: 3.18
./configure '--disable-debug' '--enable-force-cgi-redirect' '--enable-track-vars' '--with-config-file-path=/etc/httpd/conf' '--enable-sysvsem' '--enable-sysvshm' '--with-mysql'

I am using the standard php ini files (php.ini-dist and php3.ini-dist) with no changes in both tests.  Please advise.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-03-25 17:14 UTC] elixer@php.net
Looking at http://www.php.net/manual/en/language.operators.precedence.php I see that the comparison operators have lower precendence than the negation operator, so in essence you are saying that the following two expressions should be equivalent:

(!$a) == $b
  $a  != $b

Is that correct?

Sean
 [2001-03-25 18:26 UTC] ying at zippydesign dot com
Hmm.. when you put it that way, I guess not :)  However, I was just caught by surpise between how this differed between PHP 4.04 and PHP 3.0.18 (and even with earlier versions of PHP4).  And, indeed ($a != $b) is the better, less ambiguous, way to write this statement.  Thanks.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 09:01:28 2024 UTC