szepeviktor/phpstan-wordpress

`wp_die()` not exclusively an early terminating function

Closed this issue ยท 4 comments

wp_die() is treated as if it terminated script execution early:

earlyTerminatingFunctionCalls:
- wp_die

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.