Repository navigation
Code Modernization: Use the null coalescing assignment operator in option.php - #16005
noruzzamans wants to merge 1 commit into
Conversation
…tion.php Replaces verbose `! isset()` guard blocks that assign default values in `get_transient()` and `get_site_transient()` with the null coalescing assignment operator (`??=`) in `src/wp-includes/option.php`: - `$value ??= get_option( $transient_option );` in `get_transient()` - `$value ??= get_site_option( $transient_option );` in `get_site_transient()` **Why this is safe** - `??=` requires PHP 7.4, which is the minimum supported version for WordPress Core. - `??=` and `! isset()` test the exact same condition, applying the default only when `$value` is unset or null. - Assignment order and fallback logic are preserved identically across both transient functions. - Purely internal code simplification with no behavioral or architectural changes. Props noruzzaman. See #65823.
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are recorded for the transient fallback assignment simplification.
No open issues 🎉
What changed in this PR
Modernizes fallback retrieval in WordPress Core’s transient functions without changing unset-or-null handling.
Changes:
- Replaces
! isset()assignment guards with??=inget_transient()andget_site_transient(). - Preserves conditional fallback calls to
get_option()andget_site_option().
| File | Description |
|---|---|
src/wp-includes/option.php |
Simplifies two transient fallback assignments using ??=. |
Review effort: Balanced
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. Props Bot commandsYou can trigger Props Bot actions by commenting on this PR:
|
Description
Replaces verbose
! isset()guard blocks that assign default values with the null coalescing assignment operator (??=) insrc/wp-includes/option.php:Scope
This covers
get_transient()andget_site_transient()insrc/wp-includes/option.phpcompletely. Both transient functions normalize their fallback retrieval using the exact same idiom, making both functions internally consistent. 2 guard blocks replaced, 6 lines removed for 2 added (-4 net lines).Why this is safe
??=requires PHP 7.4, which is the minimum supported version for WordPress Core.??=and! isset()test the exact same condition, applying the default only when$valueis unset or null.Trac ticket: https://core.trac.wordpress.org/ticket/65823