Skip to content

Narrow return type of wp_get_environment_type - #499

Merged
szepeviktor merged 1 commit into
php-stubs:masterfrom
s-a-s-k-i-a:fix/wp-get-environment-type-return-type
Nov 1, 2026
Merged

szepeviktor merged 1 commit into
php-stubs:masterfrom
s-a-s-k-i-a:fix/wp-get-environment-type-return-type

Conversation

@s-a-s-k-i-a

Copy link
Copy Markdown
Contributor

wp_get_environment_type() only returns one of four values: 'local', 'development', 'staging' or 'production'. WordPress checks the value against this fixed list and falls back to 'production' for anything else. There is no filter.

The stubs still say string. This PR adds the four values to functionMap.php, the same way #296 did for wp_get_server_protocol().

With this, PHPStan reports a typo like wp_get_environment_type() === 'dev' as always false.

Changes

  • functionMap.php: new entry for wp_get_environment_type.
  • wordpress-stubs.php: regenerated with ./generate.sh.
  • tests/data/return/wp-get-environment-type.php: new return type test.

Testing

  • composer run test passes locally on PHP 8.2, 8.4 and 8.5.
  • The new test fails with the old stubs and passes with the new ones.
  • The Integrate and Spelling workflows pass on my fork.

AI-assisted (Claude). I reviewed and tested the change.

wp_get_environment_type() reads WP_ENVIRONMENT_TYPE from the environment or
the constant and checks it against a fixed list. Any other value becomes
'production'. The static cache is validated before every return, and no
call can read it in between. There is no filter. The function therefore
always returns 'local', 'development', 'staging' or 'production'.
@s-a-s-k-i-a
s-a-s-k-i-a marked this pull request as ready for review November 1, 2026 09:09
@szepeviktor

Copy link
Copy Markdown
Member

Thank you.

@szepeviktor
szepeviktor merged commit e257cfc into php-stubs:master Nov 1, 2026
8 checks passed
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