com php-src: Improved fix for Fully qualified (leading backslash) type names must fail: NEWS Zend/tests/typehints/fully_qualified_ array.phpt
Zend/tests/typehints/fully_qualified_scalar .phpt Zend/zend_compile.c Zend/zend_language_pars er.y
| From: | Xinchen Hui | Date: | Wed, 25 Nov 2015 03:27:32 +0000 |
| Subject: | com php-src: Improved fix for Fully qualified (leading backslash) type names must fail: NEWS Zend/tests/typehints/fully_qualified_ array.phpt Zend/tests/typehints/fully_qualified_scalar .phpt Zend/zend_compile.c Zend/zend_language_pars er.y |
||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-90016@lists.php.net to get a copy of this message | ||
Commit: 00865ae22f2c5fdee9e500ce79d442467e0a0899
Author: Xinchen Hui <laruence@gmail.com> Wed, 25 Nov 2015 11:27:32 +0800
Parents: 7be30eb78c874bf887f5d2aee290f44d2febfa3d
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=00865ae22f2c5fdee9e500ce79d442467e0a0899
Log:
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
Changed paths:
M NEWS
A Zend/tests/typehints/fully_qualified_array.phpt
M Zend/tests/typehints/fully_qualified_scalar.phpt
M Zend/zend_compile.c
M Zend/zend_language_parser.y
Diff:
diff --git a/NEWS b/NEWS
index ea2e239..27a4e5c 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 0000000..b1d32e7
--- /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 fcc4360..bdc3fbf 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 201afd0..73f21a8 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 3fc6494..ed7af7e 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; }
;