com php-src: Disallow relative namespace type declarations: Zend/tests/typehints/scalar_relative_typehint_disallowed .phpt Zend/zend_compile.c
| From: | Dmitry Stogov | Date: | Thu, 19 Mar 2015 18:07:03 +0000 |
| Subject: | com php-src: Disallow relative namespace type declarations: Zend/tests/typehints/scalar_relative_typehint_disallowed .phpt Zend/zend_compile.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-85679@lists.php.net to get a copy of this message | ||
Commit: aaf0c8b594f1ddcd090123fff3734b0aa1eeccd9
Author: Anthony Ferrara <ircmaxell@gmail.com> Thu, 19 Mar 2015 14:07:03 -0400
Parents: 62fc556764a6a4b7ed010d09b2d8baed6c2ed01b
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=aaf0c8b594f1ddcd090123fff3734b0aa1eeccd9
Log:
Disallow relative namespace type declarations
Changed paths:
M Zend/tests/typehints/scalar_relative_typehint_disallowed.phpt
M Zend/zend_compile.c
Diff:
diff --git a/Zend/tests/typehints/scalar_relative_typehint_disallowed.phpt
b/Zend/tests/typehints/scalar_relative_typehint_disallowed.phpt
index 0aea1ae...30d2bd8 100644
--- a/Zend/tests/typehints/scalar_relative_typehint_disallowed.phpt
+++ b/Zend/tests/typehints/scalar_relative_typehint_disallowed..phpt
@@ -11,4 +11,4 @@ foo(10);
?>
--EXPECTF--
-Fatal error: Argument 1 passed to foo() must be an instance of bar\int, integer given, called in %s
on line %d and defined in %s on line %d
\ No newline at end of file
+Fatal error: "bar\int" cannot be used as a type declaration in %s on line %d
\ No newline at end of file
diff --git a/Zend/zend_compile..c b/Zend/zend_compile.c
index 954412b..abdfc37 100644
--- a/Zend/zend_compile.c
+++ b/Zend/zend_compile.c
@@ -146,9 +146,16 @@ static const scalar_typehint_info scalar_typehints[] = {
static zend_always_inline const scalar_typehint_info* zend_find_scalar_typehint(const zend_string
*const_name) /* {{{ */
{
const scalar_typehint_info *info = &scalar_typehints[0];
+ const char *uqname;
+ size_t uqname_len;
+
+ if (!zend_get_unqualified_name(const_name, &uqname, &uqname_len)) {
+ uqname = const_name->val;
+ uqname_len = const_name->len;
+ }
while (info->name) {
- if (const_name->len == info->name_len && zend_binary_strcasecmp(const_name->val,
const_name->len, info->name, info->name_len) == 0) {
+ if (uqname_len == info->name_len && zend_binary_strcasecmp(uqname, uqname_len,
info->name, info->name_len) == 0) {
break;
}
info++;
@@ -177,6 +184,9 @@ static zend_always_inline zend_uchar zend_lookup_scalar_typehint_by_name(const z
const scalar_typehint_info *info = zend_find_scalar_typehint(const_name);
if (info) {
+ if (const_name->len != info->name_len) {
+ zend_error_noreturn(E_COMPILE_ERROR, "\"%s\" cannot be used as a type
declaration", const_name->val);
+ }
return info->type;
} else {
return 0;