summaryrefslogtreecommitdiff
path: root/ext/reflection
diff options
context:
space:
mode:
authorMáté Kocsis <kocsismate@woohoolabs.com>2020-03-27 23:39:49 +0100
committerMáté Kocsis <kocsismate@woohoolabs.com>2020-05-22 16:08:12 +0200
commitaec4c0fd031ad557527ff6c888a1b60048bb1cdc (patch)
tree2f437957be3862d543c45a2db6c4e5e44f9ff1df /ext/reflection
parent4bc1d8333aa8b40a6c6fe89762f6b5a4bd309a1c (diff)
downloadphp-git-aec4c0fd031ad557527ff6c888a1b60048bb1cdc.tar.gz
Add support for the mixed type
RFC: https://wiki.php.net/rfc/mixed_type_v2 Closes GH-5313 Co-authored-by: Dan Ackroyd <danack@basereality.com>
Diffstat (limited to 'ext/reflection')
-rw-r--r--ext/reflection/php_reflection.c6
-rw-r--r--ext/reflection/tests/mixed_type.phpt32
2 files changed, 35 insertions, 3 deletions
diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c
index 1ed057d902..9aac065e38 100644
--- a/ext/reflection/php_reflection.c
+++ b/ext/reflection/php_reflection.c
@@ -1187,13 +1187,13 @@ static void reflection_type_factory(zend_type type, zval *object, zend_bool lega
reflection_object *intern;
type_reference *reference;
zend_bool is_union = is_union_type(type);
+ zend_bool is_mixed = ZEND_TYPE_PURE_MASK(type) == MAY_BE_ANY;
- reflection_instantiate(
- is_union ? reflection_union_type_ptr : reflection_named_type_ptr, object);
+ reflection_instantiate(is_union && !is_mixed ? reflection_union_type_ptr : reflection_named_type_ptr, object);
intern = Z_REFLECTION_P(object);
reference = (type_reference*) emalloc(sizeof(type_reference));
reference->type = type;
- reference->legacy_behavior = legacy_behavior && !is_union;
+ reference->legacy_behavior = legacy_behavior && !is_union && !is_mixed;
intern->ptr = reference;
intern->ref_type = REF_TYPE_TYPE;
diff --git a/ext/reflection/tests/mixed_type.phpt b/ext/reflection/tests/mixed_type.phpt
new file mode 100644
index 0000000000..d44b91789c
--- /dev/null
+++ b/ext/reflection/tests/mixed_type.phpt
@@ -0,0 +1,32 @@
+--TEST--
+Test that the mixed type is reflectable
+--FILE--
+<?php
+class A
+{
+ public mixed $a;
+
+ public function test(mixed $a): mixed {}
+}
+
+$a = new A();
+
+$object = new ReflectionObject($a);
+$method = new ReflectionMethod($a, "test");
+
+var_dump($object->getProperty("a")->getType()->getName());
+var_dump($method->getParameters()[0]->getType()->getName());
+var_dump($method->getReturnType()->getName());
+
+var_dump((string) $object->getProperty("a")->getType());
+var_dump((string) $method->getParameters()[0]->getType());
+var_dump((string) $method->getReturnType());
+
+?>
+--EXPECT--
+string(5) "mixed"
+string(5) "mixed"
+string(5) "mixed"
+string(5) "mixed"
+string(5) "mixed"
+string(5) "mixed"