]> granicus.if.org Git - php/commitdiff
Disallow relative namespace type declarations
authorAnthony Ferrara <ircmaxell@gmail.com>
Thu, 19 Mar 2015 18:07:03 +0000 (14:07 -0400)
committerAnthony Ferrara <ircmaxell@gmail.com>
Thu, 19 Mar 2015 18:07:03 +0000 (14:07 -0400)
Zend/tests/typehints/scalar_relative_typehint_disallowed.phpt
Zend/zend_compile.c

index 0aea1aedfb5ddb21ec6b38a245759dc8a25a33da..30d2bd8b745b81a4c37a6042b41b9b6e52780632 100644 (file)
@@ -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
index 954412bf19fff310bc03492fb0408a64876aa41c..abdfc3703b995f8fa76730f59334d9e975fcd945 100644 (file)
@@ -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;