PHP8 specific removed create_function error#588
PHP8 specific removed create_function error#588mglaman wants to merge 1 commit intophpstan:masterfrom
Conversation
| if (!$this->reflectionProvider->hasFunction($node->name, $scope)) { | ||
| // @todo this feels a bit hacky, maybe we need a repository of | ||
| // functions that are removed based on version level? | ||
| if ($this->phpVersion->getVersionId() >= 80000 && (string) $node->name === 'create_function') { |
There was a problem hiding this comment.
We already have that: https://github.com/JetBrains/phpstorm-stubs/blob/5cae90f74aa33a4cdbeb4da654525fe665e735c9/Core/Core.php#L755-L768
PHPStan should currently read the @removed annotation That's done here: https://github.com/ondrejmirtes/BetterReflection/blob/348a8777d11b9dd88f13e0d99a84d1671a8cf8a7/src/SourceLocator/SourceStubber/PhpStormStubsSourceStubber.php#L410-L417
But it's probably skipped or unused for functions. It works for classes+methods because RuntimeReflectionProvider is skipped in here:
But RuntimeReflectionProvider isn't skipped for functions:
Try to prototype some code in the last location to see if you get anywhere and the function is detected as removed.
You could try to check PhpStormStubsSourceStubber::isPresentFunction() === false which should say that the function no longer exists on PHP 8 and skip in that case.
|
Oh, I haven't noticed this is actually already reported on PHP 8: https://phpstan.org/r/7b7db20f-8b1d-411d-9d9e-41dbec9bae4d So all of my advice here is actually outdated, it already works. So I don't think it's worth doing a special message about this in PHPStan - the fact that the function does not exist is correct and it's up to the user to educate themselves about it. I understand why you'd want a special message here, but I don't think that widening the scope of this tool is worth it - it would take too much effort to explain everything like this when PHP manual does already a good job at this. |
|
And the reason why this works is this line in RuntimeReflectionProvider: phpstan-src/src/Reflection/Runtime/RuntimeReflectionProvider.php Lines 314 to 316 in 1501229 |
|
+1 to closing this. Fixing phpstan/phpstan#5373 and getting core functions to report deprecation is a better step. |
Part of phpstan/phpstan#5368
This handles an improved error message when running on PHP8 to explain why the function no longer exists.