]> granicus.if.org Git - php/commitdiff
Support void return type in reflection
authorAndrea Faulds <ajf@ajf.me>
Thu, 28 Jan 2016 18:01:48 +0000 (18:01 +0000)
committerAndrea Faulds <ajf@ajf.me>
Thu, 28 Jan 2016 18:01:48 +0000 (18:01 +0000)
ext/reflection/php_reflection.c
ext/reflection/tests/ReflectionType_possible_types.phpt [new file with mode: 0644]

index 461104f394ada647a100f8dcded331b15540f003..af1e972f604a64d10b66f53e54a238a48c9946ed 100644 (file)
@@ -3029,6 +3029,7 @@ ZEND_METHOD(reflection_type, __toString)
                case _IS_BOOL:    RETURN_STRINGL("bool", sizeof("bool") - 1);
                case IS_LONG:     RETURN_STRINGL("int", sizeof("int") - 1);
                case IS_DOUBLE:   RETURN_STRINGL("float", sizeof("float") - 1);
+               case IS_VOID:     RETURN_STRINGL("void", sizeof("void") - 1);
                EMPTY_SWITCH_DEFAULT_CASE()
        }
 }
diff --git a/ext/reflection/tests/ReflectionType_possible_types.phpt b/ext/reflection/tests/ReflectionType_possible_types.phpt
new file mode 100644 (file)
index 0000000..9f876cb
--- /dev/null
@@ -0,0 +1,29 @@
+--TEST--
+ReflectionType possible types
+--FILE--
+<?php
+
+$functions = [
+    function(): int {},
+    function(): float {},
+    function(): string {},
+    function(): bool {},
+    function(): array {},
+    function(): callable {},
+    function(): StdClass {}
+];
+
+foreach ($functions as $function) {
+    $reflectionFunc = new ReflectionFunction($function);
+    $returnType = $reflectionFunc->getReturnType();
+    var_dump($returnType->__toString());
+}
+?>
+--EXPECTF--
+string(3) "int"
+string(5) "float"
+string(6) "string"
+string(4) "bool"
+string(5) "array"
+string(8) "callable"
+string(8) "StdClass"