Build/Test Tools: Treat request-scoped constants as dynamic in PHPStan - #13071
Open
tstokes8040 wants to merge 1 commit into
Open
Build/Test Tools: Treat request-scoped constants as dynamic in PHPStan#13071tstokes8040 wants to merge 1 commit into
tstokes8040 wants to merge 1 commit into
Conversation
`DOING_AJAX`, `DOING_CRON`, `REST_REQUEST`, `WP_INSTALLING`, `WP_INSTALLING_NETWORK`, `WP_REPAIRING` and `XMLRPC_REQUEST` are each defined only as the literal `true` within the analyzed tree, so PHPStan concluded that the right side of the `defined( 'X' ) && X` idiom can never be falsy. Every one of them is request-scoped: absent on most requests, and definable by a plugin or by `wp-config.php` before load. Listing them in `dynamicConstantNames` stops PHPStan assuming a value it cannot know.
This resolves 11 `booleanAnd.rightAlwaysTrue` occurrences, in `wp-admin/includes/schema.php`, `wp-includes/functions.php`, `wp-includes/l10n.php`, `wp-includes/load.php` and `wp-includes/user.php`, leaving 5 in the baseline. It was regenerated with:
{{{
composer phpstan:baselines -- --identifier=booleanAnd.rightAlwaysTrue
}}}
Follow-up to [63191].
Props tstokes8040.
See #65817.
|
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. |
This was referenced Aug 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
DOING_AJAX,DOING_CRON,REST_REQUEST,WP_INSTALLING,WP_INSTALLING_NETWORK,WP_REPAIRINGandXMLRPC_REQUESTare each defined only as the literaltruewithin the analyzed tree, so PHPStan concluded that the right side of thedefined( 'X' ) && Xidiom can never be falsy:DOING_AJAXwp-admin/admin-ajax.php:16DOING_CRONwp-cron.php:42REST_REQUESTwp-includes/rest-api.php:478WP_INSTALLINGwp-admin/install.php:32WP_INSTALLING_NETWORKwp-admin/network.php:13WP_REPAIRINGwp-admin/maint/repair.php:8XMLRPC_REQUESTxmlrpc.php:13That conclusion is correct about the code PHPStan can see and wrong about reality. Every one of these is request-scoped: absent on most requests, defined only by the front controller handling that particular kind of request, and definable by a plugin or by
wp-config.phpbefore load. Thedefined( 'X' ) && Xguard is doing real work, and the constants belong indynamicConstantNamesalongside the ones already listed there.This resolves 11
booleanAnd.rightAlwaysTrueoccurrences, leaving 5 in the baseline:wp-admin/includes/schema.phpwp-includes/functions.phpwp-includes/l10n.phpwp-includes/load.phpwp-includes/user.phpThe baseline is generated, not hand-edited; it was regenerated with
composer phpstan:baselines -- --identifier=booleanAnd.rightAlwaysTrue.No source file is touched, so there is no runtime behaviour to change. Follow-up to [63191], which added
DB_COLLATEandWP_DEVELOPMENT_MODEfor the same reason.Testing instructions
npm run typecheck:phpontrunkreports[OK] No errors, because the occurrences are baselined.npm run typecheck:phpreports[OK] No errorsacross 1289 files, withtests/phpstan/baselines/booleanAnd.rightAlwaysTrue.neondown from 9 entries / 16 occurrences to 5 entries / 5 occurrences.booleanAnd.rightAlwaysTrue, and no new error of any identifier appears anywhere in the codebase.npm run test:php -- --group html-apiand the wider suite are unaffected, since no source file changes.Trac ticket: https://core.trac.wordpress.org/ticket/65817
Use of AI Tools
AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 5
Used for: grouping the remaining boolean PHPStan baselines by root cause, identifying this cluster and the constants behind it, measuring the before/after error diff across the whole codebase, regenerating the baseline, and drafting this description. The change itself and the verification runs were reviewed and confirmed by me in a local development environment.
Count of removed errors: 1