Skip to content

Conversation

@IanDelMar
Copy link
Contributor

This PR removes the WP_CLI constant from the dynamicConstantNames list in extension.neon, as it is not defined by WordPress (see this GitHub search), but rather by WP-CLI.

Including WP_CLI in the dynamicConstantNames list prevents PHPStan from reporting the following code:

if (WP_CLI) {
    // do something
}

If WP_CLI is not defined, this will trigger a fatal error in PHP 8+.

Those using WP-CLI can easily add the WP_CLI constant to their own configuration. Therefore, this package should not prevent PHPStan from reporting potential fatal errors for some users.

Related #287

@szepeviktor
Copy link
Owner

szepeviktor commented Jul 7, 2025

@IanDelMar Thank you.

Have you ever seen if (WP_CLI)?

@IanDelMar
Copy link
Contributor Author

No, I have not. It is just an example. Any fetch will result in the aforementioned fatal error if WP_CLI is not defined and not guarded by defined(). We should not instruct PHPStan to ignore cases it is intended to detect.

@szepeviktor
Copy link
Owner

I would leave it as is.

@szepeviktor szepeviktor merged commit 2e318cb into szepeviktor:2.x Jul 7, 2025
1 of 2 checks passed
@IanDelMar IanDelMar deleted the WP_CLI branch July 7, 2025 19:11
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