]> granicus.if.org Git - php/commitdiff
Improved fix for Fully qualified (leading backslash) type names must fail
authorXinchen Hui <laruence@gmail.com>
Wed, 25 Nov 2015 03:27:32 +0000 (11:27 +0800)
committerXinchen Hui <laruence@gmail.com>
Wed, 25 Nov 2015 03:27:32 +0000 (11:27 +0800)
it now all fails with COMPILE_ERROR instead of syntax error for T_ARRAY
but COMPILE_ERROR for int

NEWS
Zend/tests/typehints/fully_qualified_array.phpt [new file with mode: 0644]
Zend/tests/typehints/fully_qualified_scalar.phpt
Zend/zend_compile.c
Zend/zend_language_parser.y

diff --git a/NEWS b/NEWS
index ea2e23934c0babc28399731c9c52951c98914234..27a4e5c8fded99c1f126a8d0a0f191195a87053d 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -18,7 +18,7 @@ PHP                                                                        NEWS
   . 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)
+    to not be accepted as type name. (Bob, Laruence)
   . Fixed bug #70904 (yield from incorrectly marks valid generator as finished).
     (Bob)
 
diff --git a/Zend/tests/typehints/fully_qualified_array.phpt b/Zend/tests/typehints/fully_qualified_array.phpt
new file mode 100644 (file)
index 0000000..b1d32e7
--- /dev/null
@@ -0,0 +1,13 @@
+--TEST--
+Fully qualified (leading backslash) type names must fail
+--FILE--
+<?php
+
+function foo(\array $foo) {
+       var_dump($foo);
+}
+foo(1);
+
+?>
+--EXPECTF--
+Fatal error: Cannot use the builtin type 'array' as fully qualified with a leading backslash in %s on line %d
index fcc4360e76e7d18f94428ad2a4752899ed033f62..bdc3fbf476bd0e3255918595de30bf3f6bf63a3b 100644 (file)
@@ -10,4 +10,4 @@ foo(1);
 
 ?>
 --EXPECTF--
-Fatal error: Cannot use the scalar type 'int' as fully qualified with a leading backslash in %s on line %d
+Fatal error: Cannot use the builtin type 'int' as fully qualified with a leading backslash in %s on line %d
index 201afd07cdf858cbbbe122036702656bafd5c284..73f21a8248ab9fd65831cef4d8a78c69fc675619 100644 (file)
@@ -4384,7 +4384,7 @@ static void zend_compile_typename(zend_ast *ast, zend_arg_info *arg_info) /* {{{
 
                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));
+                               zend_error_noreturn(E_COMPILE_ERROR, "Cannot use the builtin type '%s' as fully qualified with a leading backslash", ZSTR_VAL(zend_string_tolower(class_name)));
                        }
                        arg_info->type_hint = type;
                } else {
index 3fc64947020f21f227fe79a45c6b5dd1022d035f..ed7af7e55daec3c78e4eed2f24747e26199df0b8 100644 (file)
@@ -643,6 +643,12 @@ optional_type:
 type:
                T_ARRAY         { $$ = zend_ast_create_ex(ZEND_AST_TYPE, IS_ARRAY); }
        |       T_CALLABLE      { $$ = zend_ast_create_ex(ZEND_AST_TYPE, IS_CALLABLE); }
+       |       T_NS_SEPARATOR T_ARRAY
+                                       { $$ = NULL; zend_error_noreturn(E_COMPILE_ERROR,
+                                               "Cannot use the builtin type 'array' as fully qualified with a leading backslash"); }
+       |       T_NS_SEPARATOR T_CALLABLE
+                                       { $$ = NULL; zend_error_noreturn(E_COMPILE_ERROR,
+                                               "Cannot use the builtin type 'callable' as fully qualified with a leading backslash"); }
        |       name            { $$ = $1; }
 ;