diff --git a/src/Reflection/Php/PhpMethodReflection.php b/src/Reflection/Php/PhpMethodReflection.php index b141bcec7e..e9e8db3916 100644 --- a/src/Reflection/Php/PhpMethodReflection.php +++ b/src/Reflection/Php/PhpMethodReflection.php @@ -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() + ? new StringType() + : TypehintHelper::decideTypeFromReflection( + $returnType, + null, + $this->declaringClass, + ); } if ($name === '__isset') { return $this->nativeReturnType = new BooleanType();