-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Use null coalescing operator instead of isset() in if/else statements #10711
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use null coalescing operator instead of isset() in if/else statements #10711
Conversation
Search: \bif\s*\(\s*isset\(\s*(\$.+?)\s*\)\s*\)\s*\{\s*(\$.+?)\s*=\s*\1;\s*\}\s*else\s*\{\s*\2\s*=\s*(\S*?);\s*}
Replace: $2 = $1 ?? $3;
|
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. |
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. |
42d8a9c to
dd160ef
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This pull request modernizes WordPress code by replacing traditional isset() checks with the null coalescing operator (??), making the code more concise and readable while maintaining identical behavior.
Changes:
- Replaced
if (isset($var)) { $result = $var; } else { $result = $default; }patterns with$result = $var ?? $default; - Applied this refactoring consistently across 15 files in both wp-includes and wp-admin directories
- Maintained existing code alignment and formatting conventions
Reviewed changes
Copilot reviewed 15 out of 15 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/wp-includes/theme.php | Simplified array key check for attachment_parent in header images |
| src/wp-includes/rest-api/class-wp-rest-server.php | Simplified $_SERVER['PATH_INFO'] check in request handling |
| src/wp-includes/meta.php | Simplified array key check for meta cache retrieval |
| src/wp-includes/media.php | Simplified decoding attribute check for image optimization |
| src/wp-includes/general-template.php | Simplified object property check for post type description |
| src/wp-includes/class-wp-xmlrpc-server.php | Simplified array key check for comment status in XML-RPC |
| src/wp-includes/class-wp-styles.php | Simplified object property check for media type |
| src/wp-includes/class-wp-post-type.php | Simplified array key check for permalink endpoint mask |
| src/wp-includes/class-wp-http-streams.php | Simplified Host header check in HTTP streams |
| src/wp-includes/class-wp-date-query.php | Simplified array key check for date query parameters |
| src/wp-admin/upgrade.php | Simplified $_GET['step'] check in upgrade process |
| src/wp-admin/includes/theme.php | Simplified nested array key check for theme features |
| src/wp-admin/includes/template.php | Simplified $_REQUEST['post_status'] check for post states |
| src/wp-admin/includes/post.php | Simplified array key check for post ID |
| src/wp-admin/includes/class-wp-importer.php | Simplified array key check for CLI argument parsing |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
… with `if`/`else` statements. Developed in #10711 Follow-up to [61457], [61456], [61455], [61454], [61453], [61445], [61444], [61443], [61442], [61436], [61435], [61434], [61403], [61433], [61432], [61431], [61430], [61429], [61424], [61404], [61403]. See #58874, #63430. git-svn-id: https://develop.svn.wordpress.org/trunk@61463 602fd350-edb4-49c9-b593-d223f7449a82
|
Committed in r61463. |
… with `if`/`else` statements. Developed in WordPress/wordpress-develop#10711 Follow-up to [61457], [61456], [61455], [61454], [61453], [61445], [61444], [61443], [61442], [61436], [61435], [61434], [61403], [61433], [61432], [61431], [61430], [61429], [61424], [61404], [61403]. See #58874, #63430. Built from https://develop.svn.wordpress.org/trunk@61463 git-svn-id: http://core.svn.wordpress.org/trunk@60775 1a063a9b-81f0-0310-95a4-ce76da25c4cd
… with `if`/`else` statements. Developed in WordPress/wordpress-develop#10711 Follow-up to [61457], [61456], [61455], [61454], [61453], [61445], [61444], [61443], [61442], [61436], [61435], [61434], [61403], [61433], [61432], [61431], [61430], [61429], [61424], [61404], [61403]. See #58874, #63430. Built from https://develop.svn.wordpress.org/trunk@61463 git-svn-id: https://core.svn.wordpress.org/trunk@60775 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Search:
\bif\s*\(\s*isset\(\s*(\$.+?)\s*\)\s*\)\s*\{\s*(\$.+?)\s*=\s*\1;\s*\}\s*else\s*\{\s*\2\s*=\s*(\S*?);\s*}Replace:
$2 = $1 ?? $3;Trac ticket: https://core.trac.wordpress.org/ticket/58874
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.