Skip to content

Only set return native type from null return type when declaring class is built in on __toString() #3978

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 8 commits into from
8 changes: 7 additions & 1 deletion src/Reflection/Php/PhpMethodReflection.php
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,13 @@ private function getNativeReturnType(): Type
return $this->nativeReturnType = new VoidType();
}
if ($name === '__tostring') {
return $this->nativeReturnType = new StringType();
return $this->nativeReturnType = $this->declaringClass->isBuiltin()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. How is __toString() different from other methods handled by this method?
  2. Personally I'd like a test + revert of the commit that changed this (3854cbc) instead of this change.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. we found by case, for current case is __toString() so don't know what other needs
  2. yes, I think revert is better for this case, as native is native on overridden method.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

? new StringType()
: TypehintHelper::decideTypeFromReflection(
$returnType,
null,
$this->declaringClass,
);
}
if ($name === '__isset') {
return $this->nativeReturnType = new BooleanType();
Expand Down
Loading