From: Xinchen Hui <laruence@gmail.com>
Date: Wed, 25 Nov 2015 03:27:32 +0000 (+0800)
Subject: Improved fix for Fully qualified (leading backslash) type names must fail
X-Git-Tag: php-7.0.1RC1~48^2~6
X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=00865ae22f2c5fdee9e500ce79d442467e0a0899;p=php

Improved fix for Fully qualified (leading backslash) type names must fail

it now all fails with COMPILE_ERROR instead of syntax error for T_ARRAY
but COMPILE_ERROR for int
---

diff --git a/NEWS b/NEWS
index ea2e23934c..27a4e5c8fd 100644
--- 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
index 0000000000..b1d32e70fd
--- /dev/null
+++ b/Zend/tests/typehints/fully_qualified_array.phpt
@@ -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
diff --git a/Zend/tests/typehints/fully_qualified_scalar.phpt b/Zend/tests/typehints/fully_qualified_scalar.phpt
index fcc4360e76..bdc3fbf476 100644
--- a/Zend/tests/typehints/fully_qualified_scalar.phpt
+++ b/Zend/tests/typehints/fully_qualified_scalar.phpt
@@ -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
diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c
index 201afd07cd..73f21a8248 100644
--- a/Zend/zend_compile.c
+++ b/Zend/zend_compile.c
@@ -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 {
diff --git a/Zend/zend_language_parser.y b/Zend/zend_language_parser.y
index 3fc6494702..ed7af7e55d 100644
--- a/Zend/zend_language_parser.y
+++ b/Zend/zend_language_parser.y
@@ -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; }
 ;