`wp_die()` not exclusively an early terminating function
Closed this issue ยท 4 comments
wp_die()
is treated as if it terminated script execution early:
phpstan-wordpress/extension.neon
Lines 126 to 127 in 76f7835
But for wp_die('', '', ['exit' => false])
the script execution will not be terminated in any of WP's wp_die handlers.
if (somethingIsTrue()) {
$foo = true;
} elseif (orSomethingElseIsTrue()) {
$foo = false;
} else {
wp_die('', '', ['exit' => false])
}
doFoo($foo); // won't catch possibly undefined variable $foo
WordPress is so weird PHPStan cannot follow.
There seems to be no setEarlyTerminating
method in PHPStan.
https://github.com/search?q=repo%3Aphpstan%2Fphpstan-src%20earlyTerminating&type=code
What is your plan?
Never use ['exit' => false]
again? ๐
What is your plan? Never use
['exit' => false]
again? ๐
๐
Don't know. Maybe putting 'wp_die' => ['($args is not non-empty-array ? never : void)'],
into the functionMap.php of WordPress stubs?
Or adding an extension checking for the exit key in $args
and then either use the never or the void type.
Okay!
I am in!
Please add that and add a few (2) tests too.
Thank you.
Related php-stubs/wordpress-stubs#36