mirror of
https://github.com/php/php-src.git
synced 2024-09-21 18:07:23 +00:00
Fixed bug #80190
This commit is contained in:
parent
d9dce839f7
commit
dee802498e
4
NEWS
4
NEWS
@ -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)
|
||||
|
@ -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);
|
||||
}
|
||||
|
67
ext/reflection/tests/bug80190.phpt
Normal file
67
ext/reflection/tests/bug80190.phpt
Normal 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)
|
Loading…
Reference in New Issue
Block a user