This commit is contained in:
Nikita Popov 2020-10-06 10:20:27 +02:00
parent d9dce839f7
commit dee802498e
3 changed files with 74 additions and 0 deletions

4
NEWS
View File

@ -10,6 +10,10 @@ PHP NEWS
. Fixed bug #80184 (Complex expression in while / if statements resolves to
false incorrectly). (Nikita)
- Reflection:
. Fixed bug #80190 (ReflectionMethod::getReturnType() does not handle static
as part of union type). (Nikita)
- SPL:
. Fixed bug #65387 (Circular references in SPL iterators are not garbage
collected). (Nikita)

View File

@ -2952,6 +2952,9 @@ ZEND_METHOD(ReflectionUnionType, getTypes)
type_mask = ZEND_TYPE_PURE_MASK(param->type);
ZEND_ASSERT(!(type_mask & MAY_BE_VOID));
if (type_mask & MAY_BE_STATIC) {
append_type_mask(return_value, MAY_BE_STATIC);
}
if (type_mask & MAY_BE_CALLABLE) {
append_type_mask(return_value, MAY_BE_CALLABLE);
}

View File

@ -0,0 +1,67 @@
--TEST--
Bug #80190: ReflectionMethod::getReturnType() does not handle static as part of union type
--FILE--
<?php
class C
{
public function a(): self
{
}
public function b(): stdClass|self
{
}
public function c(): static
{
}
public function d(): stdClass|static
{
}
}
foreach ((new ReflectionClass(C::class))->getMethods() as $method) {
print $method->getDeclaringClass()->getName() . '::' . $method->getName() . '()' . PHP_EOL;
print ' $method->getReturnType() returns ' . get_class($method->getReturnType()) . PHP_EOL;
print ' $method->getReturnType()->__toString() returns ' . $method->getReturnType() . PHP_EOL;
if ($method->getReturnType() instanceof ReflectionUnionType) {
print ' $method->getReturnType()->getTypes() returns an array with ' . count($method->getReturnType()->getTypes()) . ' element(s)' . PHP_EOL;
print ' type(s) in union: ';
$types = [];
foreach ($method->getReturnType()->getTypes() as $type) {
$types[] = get_class($type) . "($type)";
}
print join(', ', $types) . PHP_EOL;
}
print PHP_EOL;
}
?>
--EXPECT--
C::a()
$method->getReturnType() returns ReflectionNamedType
$method->getReturnType()->__toString() returns self
C::b()
$method->getReturnType() returns ReflectionUnionType
$method->getReturnType()->__toString() returns stdClass|self
$method->getReturnType()->getTypes() returns an array with 2 element(s)
type(s) in union: ReflectionNamedType(stdClass), ReflectionNamedType(self)
C::c()
$method->getReturnType() returns ReflectionNamedType
$method->getReturnType()->__toString() returns static
C::d()
$method->getReturnType() returns ReflectionUnionType
$method->getReturnType()->__toString() returns stdClass|static
$method->getReturnType()->getTypes() returns an array with 2 element(s)
type(s) in union: ReflectionNamedType(stdClass), ReflectionNamedType(static)