Closed (fixed)
Project:
Coding Standards
Component:
Coding Standards
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
26 Apr 2016 at 17:48 UTC
Updated:
7 Sep 2016 at 20:04 UTC
Jump to comment: Most recent
While some might not even be aware of it, PHP doesn't only have the != for weak-typed inequality but also <>. Since it is much less common, though, and also doesn't have the same visual harmony with the strong-typed inequality operator, !==, we propose to explicitly forbid its use in our coding standards, by adding the following second paragraph to the "Operators" section:
Checks for weak-typed inequality MUST use the
!=operator. The<>operator MUST NOT be used in PHP code.
Comments
Comment #2
perignon commented+1. While I learned not equals as <> I prefer !=.
Comment #3
tizzo commentedWow, I really thought that was already a standard. I double checked and don't see it. Weird.
+1
Comment #4
dawehnerRealistically +1, given https://stackoverflow.com/posts/723426/revisions but yeah != is not ANSI SQL
Comment #5
drunken monkeyI thought they were talking about SQL operators, too, but those are already regulated (although Views violates it) and it seems there indeed is a
<>PHP operator! Never heard of it before, though, nor seen it (I'm pretty sure).So, yes, definitely +1! Having this in the code somewhere would be a huge WTF.
Updating IS with a concrete proposal.
Comment #6
dawehnerOh wow, I got totally confused. +10 for that.
Comment #7
donquixote commentedGenerally +1.
Some notes that we might want to mention in the doc page:
||andorhave different operator precedence,!=and<>apparently have the same operator precedence.===or!==.Maybe this does not really belong on the "coding standards" page, but it is, I think, an important thing to learn for Drupal developers.
Comment #8
drunken monkeyI don't think we need to note that – why would we? If people shouldn't use the operator, its precedence is irrelevant. And if they are frantically searching for a reason to allow it after all, they'll soon discover there is none themselves, without us pointing it out.
That seems like a completely different issue – and one far less clear-cut, I'd say.
Comment #9
tizzo commentedComment #10
tstoecklerWould be nice to add a note about using <> for SQL to this. I was confused as well...
Comment #11
chx commented> If people shouldn't use the operator, its precedence is irrelevant
"You don't need the <> operator as its precedence is the same as != so please use !="
Comment #12
joelpittet+1
Comment #13
dawehnerComment #14
dawehnerSo this issue is now in phase 4, right?
I guess the next step is logically step 5, so let's see when something happens next.
Comment #15
jthorson commentedDiscussed at the August 9th coding standards committee meeting, and ratified.
As there were no immediately identifiable occurrences of this in core, this does not appear to affect core (i.e. is presumed as an existing defacto core policy), and is thus promoted to step 8 of the coding standards process.
Comment #16
tizzo commentedI updated the documentation, marking fixed!