Make WordPress Core

Opened 2 years ago

Closed 2 years ago

Last modified 23 months ago

#50276 closed enhancement (reported-upstream)

PHP Coding Standards - Yoda Conditionals - Absolute Phrasing

Reported by: theistand's profile theistand Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: General Keywords:
Focuses: docs, coding-standards Cc:


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.

Change History (3)

#1 @sabernhardt
2 years ago

  • Resolution set to reported-upstream
  • Status changed from new to closed

@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:

This ticket was mentioned in Slack in #core-coding-standards by dd32. View the logs.

2 years ago

#3 @desrosj
23 months ago

  • Focuses docs coding-standards added
  • Milestone Awaiting Review deleted
Note: See TracTickets for help on using tickets.