Skip to content

Commit beb1393

Browse files
committed
Check "self" (and declaring class in PHP 8.5+)
See php/php-src#18373
1 parent 63cfab0 commit beb1393

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

src/main/php/lang/reflect/Routine.class.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,15 @@ public function getReturnType(): Type {
126126
$r= $details[DETAIL_RETURNS] ?? null;
127127
return $r ? ltrim($r, '&') : null;
128128
};
129-
return Type::resolve($this->_reflect->getReturnType(), $this->resolve(), $api) ?? Type::$VAR;
129+
130+
// Check "self" (and declaring class, see https://github.com/php/php-src/issues/18373)
131+
$decl= $this->_reflect->getDeclaringClass();
132+
$type= $this->_reflect->getReturnType();
133+
if ($type instanceof \ReflectionNamedType && (PHP_VERSION_ID >= 80500 ? $decl->getName() : 'self') === $type->getName()) {
134+
return ($specific= $api()) ? Type::named($specific, $this->resolve()) : new XPClass($decl);
135+
}
136+
137+
return Type::resolve($type, $this->resolve(), $api) ?? Type::$VAR;
130138
}
131139

132140
/** Retrieve return type name */

0 commit comments

Comments
 (0)