[wp-trac] [WordPress Trac] #50276: PHP Coding Standards - Yoda Conditionals - Absolute Phrasing

WordPress Trac noreply at wordpress.org
Thu May 28 16:55:47 UTC 2020


#50276: PHP Coding Standards - Yoda Conditionals - Absolute Phrasing
-------------------------+-----------------------------
 Reporter:  theistand    |      Owner:  (none)
     Type:  enhancement  |     Status:  new
 Priority:  normal       |  Milestone:  Awaiting Review
Component:  General      |    Version:
 Severity:  normal       |   Keywords:
  Focuses:               |
-------------------------+-----------------------------
 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.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/50276>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list