Skip to content

Coding Standards: Use strict null comparison instead of is_null()#12124

Closed
Dervish12 wants to merge 1 commit into
WordPress:trunkfrom
Dervish12:trac/is-null-strict-comparison
Closed

Coding Standards: Use strict null comparison instead of is_null()#12124
Dervish12 wants to merge 1 commit into
WordPress:trunkfrom
Dervish12:trac/is-null-strict-comparison

Conversation

@Dervish12

Copy link
Copy Markdown

Summary

Replace is_null( $var ) with null === $var and ! is_null( $var ) with null !== $var across multiple core files.

WordPress Coding Standards prefer strict comparison operators over function calls for type checking. Using null === $var is functionally equivalent to is_null( $var ) but:

  • Aligns with the Yoda condition style used throughout WordPress core
  • Is consistent with how other type checks are written (e.g. false === $var)
  • Avoids the function call overhead (minor performance benefit)

Files changed (14 files, 25 replacements)

  • src/wp-includes/functions.php — 6 instances
  • src/wp-includes/blocks/navigation-link.php — 4 instances
  • src/wp-includes/blocks.php — 2 instances
  • src/wp-includes/post.php — 2 instances
  • src/wp-includes/load.php — 2 instances
  • src/wp-includes/blocks/icon.php — 1 instance
  • src/wp-includes/blocks/template-part.php — 1 instance
  • src/wp-includes/formatting.php — 1 instance
  • src/wp-includes/http.php — 1 instance
  • src/wp-includes/revision.php — 1 instance
  • src/wp-includes/class-wp-http-cookie.php — 1 instance
  • src/wp-includes/class-wp-http-proxy.php — 1 instance
  • src/wp-includes/ms-functions.php — 1 instance
  • src/wp-admin/install.php — 1 instance

Third-party libraries and files with polyfill availability concerns were intentionally excluded.

Test plan

  • Full PHPUnit test suite passes (29,457 tests, 0 failures)
  • PHPCS passes with no new violations
  • Manual verification: All null checks behave identically (strict comparison is functionally equivalent to is_null())

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.

Replace `is_null( $var )` with `null === $var` and `! is_null( $var )`
with `null !== $var` across multiple core files.

WordPress Coding Standards prefer strict comparison operators over
function calls for type checking. Using `null === $var` is functionally
equivalent to `is_null( $var )` but aligns with the Yoda condition
style used throughout WordPress core and is more consistent with how
other type checks are written (e.g. `false === $var`).

This changeset updates 14 core files, excluding third-party libraries
and files where polyfill availability is a concern.

Props Dervish12.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@github-actions

github-actions Bot commented Jun 8, 2026

Copy link
Copy Markdown

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 props-bot label.

Unlinked Accounts

The following contributors have not linked their GitHub and WordPress.org accounts: @Dervish12.

Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@github-actions

github-actions Bot commented Jun 8, 2026

Copy link
Copy Markdown

Trac Ticket Missing

This pull request is missing a link to a Trac ticket. For a contribution to be considered, there must be a corresponding ticket in Trac.

To attach a pull request to a Trac ticket, please include the ticket's full URL in your pull request description. More information about contributing to WordPress on GitHub can be found in the Core Handbook.

@westonruter

Copy link
Copy Markdown
Member

@westonruter westonruter closed this Jun 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants