Code Inspection doesn't appear to be reporting properly with PHP 8

ReflectionParameter::getClass has been deprecated in PHP 8.0. The recommended alternative includes using ReflectionType::isBuiltin. However, the Code Inspection: Element is not available in configured PHP version is being triggered with the message that "'isBuiltin' was removed in 8.0 PHP version" which is incorrect as far as I can tell considering the code functions without error using PHP 8.

I am running PhpStorm 2020.3 with PHP 8. 

Not sure if I am missing something or not. Any assistance would be appreciated.

0

Basically, this information is taken from the PhpStorm PHP lib stubs:

* @removed 8.0 this method has been removed from the {@see ReflectionType}
* class and moved to the {@see ReflectionNamedType} child.

And it looks real -- I have checked the "ReflectionType" with "get_class_methods" on PHP8 and there is no "isBuiltIn" method anymore whereas in "ReflectionNamedType" there is one.

0

That is interesting as it is not documented anywhere. Looks like both getName and isBuiltIn were moved. I am guessing the docs have not been updated yet, though the change also does not show up in the changelog either.

Based on this comment on the ReflectionType class, the change was a result of the addition of union types as there was also a ReflectionUnionType class added. And apparently, since it inherits from ReflectionType, but does not have a name or built-in check, the methods got moved to ReflectionNamedType.

I also verified similar to your check. Really wish this update had been documented somewhere.

Additionally, looking at the documentation for ReflectionParameter::getType (which is a common chain piece in code i have looked at), getType can return an instance of ReflectionType OR ReflectionNamedType (if a type is found). This went into the code with 7.1, but was not an issue since there was nothing special about ReflectionNamedType. It simply extended ReflectionType. The methods were identical as a result. 

So, what appears to be the case is technically correct in the PhpStorm PHP lib subs. The isBuiltin() method no longer exists in the ReflectionType class. However, when there is a type detected, getType returns an instance of ReflectionNamedType. The isBuiltin() method does exist there. As a result, the message is misleading even though it is saying exactly what PHP says. Not sure what would be the right way forward, but it looks like the problem is with the return of the getType() method rather than the isBuiltin() method as I thought.

0

I also was not able to find any documentation about this change and surely it is not me alone. Here is the comment from a lib stubs PR:

At the same time I discovered some new functionality that was changed, but not reflected in the documentation. Method ReflectionType::isBuiltin was removed: 

(https://github.com/JetBrains/phpstorm-stubs/pull/857#issuecomment-650842596)

 

To be honest, I doubt that there is a simple way to avoid this warning without breaking the formal logic but you may try submitting a YouTrack request for the detailed research:

https://youtrack.jetbrains.com/newIssue?project=WI

 

 

0

请先登录再写评论。