laminas-code icon indicating copy to clipboard operation
laminas-code copied to clipboard

Call to undefined method ReflectionUnionType::isBuiltin()

Open glo17680 opened this issue 2 years ago • 6 comments

Bug Report

Q A
Version(s) 4.13.0

Summary

The issue is reproduced when calling detectType() with PHP8.3. The function is mentioned as Deprecated in codebase.

File: src/Reflection/ParameterReflection.php Line:81

Screenshot 2023-12-22 at 11 42 52 AM

Error:

Screenshot 2023-12-22 at 1 21 43 PM

Current behavior

How to reproduce

Calling this function detectType() on PHP8.3 throw this error.

Expected behavior

There should be added one check if the function is not available on a particular version, the error should not be thrown.

Proposed Fix (which is working): 1- Instead of if (null !== ($type = $this->parameterReflection->getType()) && $type->isBuiltin()) {

we can fix by adding one check if (null !== ($type = $this->parameterReflection->getType()) && method_exists($type, 'isBuiltin') && $type->isBuiltin()) {

2-
And instead of if (null !== $type && $type->getName() === 'self') {

we can fix by adding one check
if (null !== $type && method_exists($type, 'getName') && $type->getName() === 'self') {

glo17680 avatar Dec 22 '23 06:12 glo17680

@glo17680 a failing test is needed

Ocramius avatar Dec 22 '23 07:12 Ocramius

@glo17680 a failing test is needed

@Ocramius please find the failed case with screenshot in the ticket description.

glo17680 avatar Dec 22 '23 07:12 glo17680

@glo17680 the expectation is for a PHPUnit test to be provided 😁

Ocramius avatar Dec 22 '23 07:12 Ocramius

@glo17680 the expectation is for a PHPUnit test to be provided 😁

@Ocramius I have attached all the required information which I have. I'm not sure for what you are asking for. Can you please confirm if any required information is missing or Is the information provided insufficient to replicate the issue ?

glo17680 avatar Dec 22 '23 09:12 glo17680

@glo17680 I think it is enough. I will work on it next weekend

devlubinets avatar Feb 12 '24 12:02 devlubinets

Note: a psalm baseline reduction would suffice.

See https://github.com/laminas/laminas-code/blob/33dd0f21ffdc157f56dd8d127fd7e67f79085de9/psalm-baseline.xml#L947-L969

Ocramius avatar May 03 '24 15:05 Ocramius