[wp-trac] [WordPress Trac] #58948: Use Elvis operator (`:?`) to replace repeating ternary patterns (`a ? a : b`)

WordPress Trac noreply at wordpress.org
Mon Jul 31 17:54:39 UTC 2023


#58948: Use Elvis operator (`:?`) to replace repeating ternary patterns (`a ? a :
b`)
-------------------------------------------+-----------------------------
 Reporter:  ayeshrajans                    |      Owner:  (none)
     Type:  enhancement                    |     Status:  new
 Priority:  normal                         |  Milestone:  Awaiting Review
Component:  General                        |    Version:  trunk
 Severity:  trivial                        |   Keywords:  has-patch
  Focuses:  performance, coding-standards  |
-------------------------------------------+-----------------------------
 This is a somewhat big change, but a simple one at that.

 Replaces `a ? a : b` patterns of ternary statements to use the Elvis
 operator `a ?: b`.

 Null coalescing operator (`??`) was added in PHP 7.0, which WordPress now
 requires as the minimum version. However, to make this ticket focused and
 easier to review, this ticket only proposes the Elvis operator.


 On tainted lines, it follows WordPress CS to use uppercase constants
 (`NULL` instead of `null`, for example), and removes a few cases of
 unnecessary braces. Apart from them, the diff output should be quite
 minimal and straight forward.


 Perhaps, the review will be easier with word-diff (`git show --word-
 diff`), or on GitHub, where it highlights word diffs in the line-diff
 mode.

 Thank you.

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


More information about the wp-trac mailing list