Repository navigation
Conversation
Replaces `isset()` and `array_key_exists()` ternaries that return the tested value or `null` (or an empty string) with the null coalescing operator (`??`), and self-referencing `$x = $x ?? $y` assignments with the null coalescing assignment operator (`??=`). For `array_key_exists()`, the only case in which the two forms differ is a key that exists with a `null` value, and both then return `null`, so every converted site is equivalent. Ternaries with a non-null fallback after `array_key_exists()` or with compound conditions, such as an additional `is_string()` check, are left as-is. Follow-up to r63609, r63633. See #65819.
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the 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. |
There was a problem hiding this comment.
🟢 Approval recommended
The test-only replacements preserve fallback and initialization behavior and are compatible with the PHP 7.4 minimum.
No open issues 🎉
What changed in this PR
Modernizes WordPress test code with null coalescing operators while preserving existing behavior.
Changes:
- Replaces value-or-fallback ternaries with
??. - Replaces self-referencing initialization assignments with
??=.
| File | Description |
|---|---|
| tests/phpunit/tests/load/wpStartScrapingEditedFileErrors.php | Simplifies request-state capture. |
| tests/phpunit/tests/load/wpIsXmlRequest.php | Simplifies header-state capture. |
| tests/phpunit/tests/load/wpIsMaintenanceMode.php | Simplifies scrape-request capture. |
| tests/phpunit/tests/load/wpIsJsonRequest.php | Simplifies header-state capture. |
| tests/phpunit/tests/load/wpGetServerProtocol.php | Simplifies protocol-state capture. |
| tests/phpunit/tests/link/getSearchLink.php | Simplifies search-query fallback. |
| tests/phpunit/tests/error-protection/wpRecoveryModeLinkService.php | Simplifies page-state capture. |
| tests/phpunit/tests/dependencies/wpPrefetchAdminAssets.php | Simplifies first-match index assignments. |
| tests/phpunit/tests/ai-client/wpAiClientEmbeddingBuilder.php | Simplifies default metadata initialization. |
| tests/phpunit/tests/admin/includes/plugin/pluginPausedState.php | Simplifies paused-plugin state capture. |
| tests/phpunit/includes/secrets/class-mock-store.php | Simplifies record lookup fallback. |
Review effort: Balanced
huzaifaalmesbah
left a comment
There was a problem hiding this comment.
Thanks for working on this, @Soean! I checked each conversion, and every array_key_exists() site falls back to null, so the behavior stays the same. Looks good to me.
AI Review: Opus 5.5
Replaces `isset()` and `array_key_exists()` ternaries that return the tested value or a fallback of `null` or `''` with the null coalescing operator (`??`), and self-referencing `$x = $x ?? $y` assignments with the null coalescing assignment operator (`??=`). **Why this is safe** - `??` and `isset()` test the same condition, so the fallback is used in exactly the same cases. - `array_key_exists()` and `??` only differ for a key that exists with a `null` value. Every converted `array_key_exists()` site falls back to `null`, so both forms return `null` in that case as well. - `??=` requires PHP 7.4, which is already the minimum supported version. - No behavior change; this is test-only code. Developed in #14616. Follow-up to r63609, r63633. Props Soean, huzaifaalmesbah. See #65819. git-svn-id: https://develop.svn.wordpress.org/trunk@64675 602fd350-edb4-49c9-b593-d223f7449a82
Replaces `isset()` and `array_key_exists()` ternaries that return the tested value or a fallback of `null` or `''` with the null coalescing operator (`??`), and self-referencing `$x = $x ?? $y` assignments with the null coalescing assignment operator (`??=`). **Why this is safe** - `??` and `isset()` test the same condition, so the fallback is used in exactly the same cases. - `array_key_exists()` and `??` only differ for a key that exists with a `null` value. Every converted `array_key_exists()` site falls back to `null`, so both forms return `null` in that case as well. - `??=` requires PHP 7.4, which is already the minimum supported version. - No behavior change; this is test-only code. Developed in WordPress/wordpress-develop#14616. Follow-up to r63609, r63633. Props Soean, huzaifaalmesbah. See #65819. Built from https://develop.svn.wordpress.org/trunk@64675 git-svn-id: http://core.svn.wordpress.org/trunk@63825 1a063a9b-81f0-0310-95a4-ce76da25c4cd
|
Comitted in r64675 ✅ |
Replaces
isset()andarray_key_exists()ternaries that return the tested value or a fallback ofnullor''with the null coalescing operator (??), and self-referencing$x = $x ?? $yassignments with the null coalescing assignment operator (??=).Why this is safe
??andisset()test the same condition, so the fallback is used in exactly the same cases.array_key_exists()and??only differ for a key that exists with anullvalue. Every convertedarray_key_exists()site falls back tonull, so both forms returnnullin that case as well.??=requires PHP 7.4, which is already the minimum supported version.Follow-up to r63609, r63633.
Trac ticket: https://core.trac.wordpress.org/ticket/65819
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.