[wp-trac] [WordPress Trac] #58874: Code Modernization: Consider using the null coalescing operator.
WordPress Trac
noreply at wordpress.org
Sat Jul 22 12:49:20 UTC 2023
#58874: Code Modernization: Consider using the null coalescing operator.
-----------------------------------+---------------------
Reporter: costdev | Owner: (none)
Type: enhancement | Status: new
Priority: normal | Milestone: 6.4
Component: General | Version:
Severity: normal | Resolution:
Keywords: has-patch 2nd-opinion | Focuses:
-----------------------------------+---------------------
Comment (by costdev):
@swissspidy @jrf I agree this should be discussed in a Make post.
> I also wonder why this should be changed for existing code (as it make
backports harder). What about just allowing it for new code and for code
which is being patched anyway ?
> That way, the impact on backports will be much more limited, while we
can still use the new shiny in code actually being worked on. 😁
I compared this to the `str_starts_with()` etc. changes a bit too much,
but I recognise that a syntax change differs from using new
functions/polyfills. I thought that updating the existing codebase would
help get contributors more used to both seeing and using the operator for
the use cases mentioned in the ticket summary. As Committers would feel an
impact that I wouldn't, I was very much looking for the exact kind of
feedback that's come so far 🙂
> Other considerations for this ticket:
> - Should this also be changed/applied when the original ternary is used
as a parameter for a function call ?
> - Should this also be changed/applied when the original ternary is used
as part of a condition in a control structure ?
> For the first I imagine it may impact readability more in a negative
way, for the second I see a risk of issues with operator precedence.
I agree that both of these may have a more negative impact that a positive
one.
> And while we are discussing this, WP, more often than not, uses a
slightly different pattern for the same
> I don't see any mention of that pattern in this ticket, while I expect
that to be far more common.
True, that case is very likely to be more common, although harder to
detect and may require closer inspection to determine whether to make the
change. I figured that for an initial change, the more straightforward use
case mentioned in the summary with ~450 instances in Core was a common
enough case that was particularly verbose.
I'm happy to move the discussion to a Make post about the PHP 7 syntaxes
when it's ready. 🙂
--
Ticket URL: <https://core.trac.wordpress.org/ticket/58874#comment:6>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list