#50276 closed enhancement (reported-upstream)
PHP Coding Standards - Yoda Conditionals - Absolute Phrasing
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Milestone: | Priority: | normal | |
| Severity: | normal | Version: | |
| Component: | General | Keywords: | |
| Focuses: | docs, coding-standards | Cc: |
Description
In the PHP coding standards page under the Yoda Conditionals it is stated
"When doing logical comparisons involving variables, always put the variable on the right side and put constants, literals, or function calls on the left side."
The concern being the use of the word "always" because at the bottom it is then stated "Yoda conditions for <, >, <=, or >= are significantly more difficult to read and are best avoided."
The issue with this is that <, >, <=, >= are in fact conditional operators and should apply to your standards with logical comparison. The emphasis "are significantly more difficult to read" implies that the decisions are on readability, however the entire purpose for the Yoda Conditionals has nothing to do with readability as it is the most illogical and unreadable implementation. The use of Yoda Conditionals should only be for ease in debugging.
Also quoting "Computer Science Terms" l-values stands for left-values and r-values stands for right-values. This is a logical approach and is a industry standard across the board which is the exact opposite as your call for use of Yoda Conditionals.
No argument on using them only pointing out some areas that can cause substantial confusion to newbies coming into the wordpress world.
@theistand Thanks for the report!
Since this is not a core bug, the ticket fits better on Meta Trac. So I copied your summary and description over there:
https://meta.trac.wordpress.org/ticket/5429