]> granicus.if.org Git - php/commitdiff
Forbid ?void
authorNikita Popov <nikic@php.net>
Sat, 4 Jun 2016 12:53:50 +0000 (14:53 +0200)
committerNikita Popov <nikic@php.net>
Sat, 4 Jun 2016 12:53:50 +0000 (14:53 +0200)
Zend/tests/type_declarations/nullable_void.phpt [new file with mode: 0644]
Zend/zend_compile.c

diff --git a/Zend/tests/type_declarations/nullable_void.phpt b/Zend/tests/type_declarations/nullable_void.phpt
new file mode 100644 (file)
index 0000000..4ff0edb
--- /dev/null
@@ -0,0 +1,11 @@
+--TEST--
+Void cannot be nullable
+--FILE--
+<?php
+
+function test() : ?void {
+}
+
+?>
+--EXPECTF--
+Fatal error: Void type cannot be nullable in %s on line %d
index 2a575cff62472d1a1ad3d53397bcdbfbbf5df268..ce8224652d028ca3a3ab81554b95f652962fac0b 100644 (file)
@@ -4964,6 +4964,10 @@ void zend_compile_params(zend_ast *ast, zend_ast *return_type_ast) /* {{{ */
 
                zend_compile_typename(return_type_ast, arg_infos);
 
+               if (arg_infos->type_hint == IS_VOID && arg_infos->allow_null) {
+                       zend_error_noreturn(E_COMPILE_ERROR, "Void type cannot be nullable");
+               }
+
                arg_infos++;
                op_array->fn_flags |= ZEND_ACC_HAS_RETURN_TYPE;
        } else {