note 101188 added to language.operators.comparison
| From: | mike dot nicewarner at gmail dot com | Date: | Wed, 01 Dec 2010 15:10:51 +0000 |
| Subject: | note 101188 added to language.operators.comparison | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-174523@lists.php.net to get a copy of this message | ||
In response to "mail at markuszeller dot com" on 4 Aug 2010, your logic is flawed. When
you put (!$a == 'hello') it evaluates the "!$a" first, then compares that result
to 'hello' as an equality. So, if you set $a to 'goodbye', the if becomes:
if (!'goodbye' == 'hello')
which is false and incorrect. Even if $a were 'hello', it would always return false. It
would never execute the code after the if statement.
The proper way to code this would be:
if (!('goodbye' == 'hello))
which would be true and correct.
However, if you do the benchmarks on this syntax, it actually takes significantly longer than the
normal ('goodbye' != 'hello') syntax.
I did this test repeatedly and confirmed my results are accurate. Please check your code. You are
probably getting incorrect results with your syntax.
----
Server IP: 69.147.83.197
Probable Submitter: 204.54.36.245
----
Manual Page -- http://www.php.net/manual/en/language.operators.comparison.php
Edit -- https://master.php.net/note/edit/101188
Del: integrated -- https://master.php.net/note/delete/101188/integrated
Del: useless -- https://master.php.net/note/delete/101188/useless
Del: bad code -- https://master.php.net/note/delete/101188/bad+code
Del: spam -- https://master.php.net/note/delete/101188/spam
Del: non-english -- https://master.php.net/note/delete/101188/non-english
Del: in docs -- https://master.php.net/note/delete/101188/in+docs
Del: other reasons-- https://master.php.net/note/delete/101188
Reject -- https://master.php.net/note/reject/101188
Search -- https://master.php.net/manage/user-notes.php