[wp-trac] [WordPress Trac] #58874: Code Modernization: Consider using the null coalescing operator.

WordPress Trac noreply at wordpress.org
Tue Sep 26 05:16:29 UTC 2023


#58874: Code Modernization: Consider using the null coalescing operator.
-------------------------------------------------+-------------------------
 Reporter:  costdev                              |       Owner:  costdev
     Type:  enhancement                          |      Status:  accepted
 Priority:  normal                               |   Milestone:  6.5
Component:  General                              |     Version:
 Severity:  normal                               |  Resolution:
 Keywords:  has-patch awaiting-php7-make-post-   |     Focuses:
  first                                          |
-------------------------------------------------+-------------------------

Comment (by dmsnell):

 Sharing my vote //for// using the `??` operator because it acts like
 `isset()` as a language opcode instead of a function call. If the variable
 it's checking doesn't exist, or if a nested key isn't around, it defaults
 to the right side of the `??` instead of throwing an exception. That is,
 it's characteristically different than `?:` because its inherently safe
 where `?:` is unsafe, as are `if` statements and the like.

 More interested in new code than updating old code, as we already have a
 high pace of refactoring old code that wasn't broken, and I recently
 caught a regression introduced during such a change. But still, for new
 code, it's a helpful construct.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/58874#comment:17>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list