]> granicus.if.org Git - php/commitdiff
Fix scalar type names with leading backslash
authorBob Weinand <bobwei9@hotmail.com>
Tue, 24 Nov 2015 20:39:06 +0000 (21:39 +0100)
committerBob Weinand <bobwei9@hotmail.com>
Tue, 24 Nov 2015 20:39:06 +0000 (21:39 +0100)
NEWS
Zend/tests/typehints/fully_qualified_scalar.phpt [new file with mode: 0644]
Zend/zend_compile.c

diff --git a/NEWS b/NEWS
index c774f0ebe636086b7c78a1c178496a4f377eb4ba..94283000ddfea08630e60ea4f4f4f0b2596e780b 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -17,6 +17,8 @@ PHP                                                                        NEWS
   . Fixed bug #70899 (buildconf failure in extensions). (Bob, Reeze)
   . Fixed bug #61751 (SAPI build problem on AIX: Undefined symbol:
     php_register_internal_extensions). (Lior Kaplan)
+  . Fixed \int (or generally every scalar type name with leading backslash)
+    to not be accepted as type name. (Bob)
 
 - Mysqlnd:
   . Fixed bug #68077 (LOAD DATA LOCAL INFILE / open_basedir restriction).
diff --git a/Zend/tests/typehints/fully_qualified_scalar.phpt b/Zend/tests/typehints/fully_qualified_scalar.phpt
new file mode 100644 (file)
index 0000000..fcc4360
--- /dev/null
@@ -0,0 +1,13 @@
+--TEST--
+Fully qualified (leading backslash) type names must fail
+--FILE--
+<?php
+
+function foo(\int $foo) {
+       var_dump($foo);
+}
+foo(1);
+
+?>
+--EXPECTF--
+Fatal error: Cannot use the scalar type 'int' as fully qualified with a leading backslash in %s on line %d
index b91fddeeb00eb948d560c01be1ea2ce47bfc9c63..201afd07cdf858cbbbe122036702656bafd5c284 100644 (file)
@@ -4383,6 +4383,9 @@ static void zend_compile_typename(zend_ast *ast, zend_arg_info *arg_info) /* {{{
                zend_uchar type = zend_lookup_builtin_type_by_name(class_name);
 
                if (type != 0) {
+                       if (ast->attr == ZEND_NAME_FQ) {
+                               zend_error_noreturn(E_COMPILE_ERROR, "Cannot use the scalar type '%s' as fully qualified with a leading backslash", ZSTR_VAL(class_name));
+                       }
                        arg_info->type_hint = type;
                } else {
                        uint32_t fetch_type = zend_get_class_fetch_type_ast(ast);