Closed Screenfeed closed 1 year ago
@IanDelMar Please hotfix this 🔥
Seems like @return never
is does not mean termination.
@IanDelMar Wait! wp_die
got no @return never
in #110!
Looks like a test is needed for assertType('*NEVER*', wp_die(''));
too (no second parameter).
Was at work. Will have a look at it now.
I added tests for wp_die()
and wp_die('')
. Both tests pass, because the extension returns "never" if the number of arguments is less than 3:
https://github.com/szepeviktor/phpstan-wordpress/blob/78db560e7989b50b05bec50ee5d862b41892654a/src/WpDieDynamicFunctionReturnTypeExtension.php#L31-L34
Okay. What could make the above code snippet fail?
@Screenfeed What is you phpstan-wordpress and wp-stubs version?
@szepeviktor Sorry I should have mentioned that in the OP.
php-stubs/wordpress-stubs v6.3.2
szepeviktor/phpstan-wordpress v1.3.1
Does PHPStan know about the dynamic return type of a function when that function is called by another function?
Does PHPStan know about the dynamic return type of a function when that function is called by another function?
Yes.
\PHPStan\dumpType(wp_die());
says NEVER.
@IanDelMar Adding back wp_die
to earlyTerminatingFunctionCalls
resolves the problem.
https://github.com/szepeviktor/phpstan-wordpress/issues/203#issuecomment-1764098309
@ondrejmirtes Could you help us?
Is there a programmatic way to mark a function early terminating?
wp_die
sometimes exits, other times not.
Look at this:
/**
* @phpstan-return never
*/
function foo() {
\PHPStan\dumpType(wp_die());
wp_die();
}
\PHPStan\dumpType(foo());
:51 Dumped type: *NEVER*
:52 Function foo() should always throw an exception or terminate script execution but doesn't do that.
:54 Dumped type: never
There is a NonAcceptingNeverType, is that the correct type to return in the extension?
Yess please!
I was wondering why it's '*NEVER*'
not just 'never'
, but was not aware that there is another never type (NonAcceptingNeverType
) and thought PHPStan will know that '*NEVER*'
is 'never'
.
WordPress will *NEVER* die()
Yeah, use new NeverType(true)
or new NonAcceptingNeverType()
. The NeverType needs to be explicit: https://github.com/phpstan/phpstan-src/blob/485922f5c2734af5af15230250340e6c1cc76451/src/Analyser/NodeScopeResolver.php#L1846-L1848
Thank you.
@Screenfeed This release is for you. https://github.com/szepeviktor/phpstan-wordpress/releases/tag/v1.3.2
@Screenfeed This release is for you. https://github.com/szepeviktor/phpstan-wordpress/releases/tag/v1.3.2
Yes! It's ok for us 👍 Thank you so much 😉
@szepeviktor Perfect. Thanks a lot to everyone! ❤️
Hello,
Sorry to bring bad news. Unless I'm missing something, it seems that something went wrong with #201.
This ends with the following message:
Versions used: