diff --git a/Library/ArgInfoDefinition.php b/Library/ArgInfoDefinition.php index 8e55bc213..e51759766 100644 --- a/Library/ArgInfoDefinition.php +++ b/Library/ArgInfoDefinition.php @@ -260,6 +260,33 @@ private function richRenderStart(): void return; } + if ($this->functionLike->isReturnTypeObject()) { + $this->codePrinter->output('#if PHP_VERSION_ID >= 80000'); + $this->codePrinter->output( + sprintf( + 'ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(%s, %d, %d, %s)', + $this->name, + (int) $this->returnByRef, + $this->functionLike->getNumberOfRequiredParameters(), + 'MAY_BE_OBJECT', + ) + ); + $this->codePrinter->output('#else'); + $this->codePrinter->output( + sprintf( + 'ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(%s, %d, %d, %s, %d)', + $this->name, + (int) $this->returnByRef, + $this->functionLike->getNumberOfRequiredParameters(), + 'IS_OBJECT', + 0, + ) + ); + $this->codePrinter->output('#endif'); + + return; + } + if (count($this->functionLike->getReturnTypes()) > 1) { $types = []; $mayBeTypes = $this->functionLike->getMayBeArgTypes(); diff --git a/Library/ClassMethod.php b/Library/ClassMethod.php index 7802cf7ce..504c2fdd5 100644 --- a/Library/ClassMethod.php +++ b/Library/ClassMethod.php @@ -712,6 +712,11 @@ public function areReturnTypesStringCompatible(): bool return isset($this->returnTypes['string']); } + public function areReturnTypesObjectCompatible(): bool + { + return isset($this->returnTypes['object']); + } + /** * Returned type hints by the method. * @@ -2323,6 +2328,7 @@ public function isReturnTypesHintDetermined(): bool $this->areReturnTypesNullCompatible() || $this->areReturnTypesStringCompatible() || $this->areReturnTypesFalseCompatible() || + $this->areReturnTypesObjectCompatible() || \array_key_exists('array', $this->getReturnTypes()) ) { continue; @@ -2350,6 +2356,16 @@ public function isReturnTypeNullableObject(): bool return count($this->returnTypes) === 2 && isset($this->returnTypes['object']) && isset($this->returnTypes['null']); } + /** + * Checks if method's return type is object `object`. + * + * @return bool + */ + public function isReturnTypeObject(): bool + { + return count($this->returnTypes) === 1 && isset($this->returnTypes['object']); + } + /** * Checks if the method have compatible return types. * diff --git a/stub/types/obj.zep b/stub/types/obj.zep index 65134b3ee..6d7254c71 100644 --- a/stub/types/obj.zep +++ b/stub/types/obj.zep @@ -12,4 +12,9 @@ class Obj { return new \stdClass(); } + + public function objectReturn() -> object + { + return new \stdClass(); + } }