summaryrefslogtreecommitdiff
path: root/ext/reflection
diff options
context:
space:
mode:
authorNikita Popov <nikita.ppv@gmail.com>2020-10-06 10:20:27 +0200
committerNikita Popov <nikita.ppv@gmail.com>2020-10-06 10:20:27 +0200
commitdee802498e25e22afb35e550dea1f7b3a8aa0129 (patch)
tree03e1d6573490837f44704a3e69e407834fc5f0bc /ext/reflection
parentd9dce839f7c7ff526ee013df5a4d5ddbf26299d8 (diff)
downloadphp-git-dee802498e25e22afb35e550dea1f7b3a8aa0129.tar.gz
Fixed bug #80190
Diffstat (limited to 'ext/reflection')
-rw-r--r--ext/reflection/php_reflection.c3
-rw-r--r--ext/reflection/tests/bug80190.phpt67
2 files changed, 70 insertions, 0 deletions
diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c
index 7b9c37d1eb..0bc4509d5e 100644
--- a/ext/reflection/php_reflection.c
+++ b/ext/reflection/php_reflection.c
@@ -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);
}
diff --git a/ext/reflection/tests/bug80190.phpt b/ext/reflection/tests/bug80190.phpt
new file mode 100644
index 0000000000..16f2fbba42
--- /dev/null
+++ b/ext/reflection/tests/bug80190.phpt
@@ -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)