summaryrefslogtreecommitdiff
path: root/Zend/zend_compile.c
diff options
context:
space:
mode:
authorNikita Popov <nikita.ppv@gmail.com>2020-09-23 13:01:07 +0200
committerNikita Popov <nikita.ppv@gmail.com>2020-09-27 10:42:58 +0200
commit5686c16db45dffb6e4898e0959f89f41cc7660f0 (patch)
treef9bc3575955b2129cf3c4c8bb1ca5607175332f8 /Zend/zend_compile.c
parent43ce7846d2378499a564fd3ffe2ffcb0ff9cb016 (diff)
downloadphp-git-5686c16db45dffb6e4898e0959f89f41cc7660f0.tar.gz
Honor strict_types=1 for attributes, improve backtraces
Make ReflectionAttribute::newInstance() respect the strict_types=1 declaration at the attribute use-site. More generally, pretend that we are calling the attribute constructor from the place where the attribute is used, which also means that the attribute location will show up properly in backtraces and inside "called in" error information. This requires us to store the attributes strict_types scope (as flags), as well as the attribute line number. The attribute filename can be recovered from the symbol it is used on. We might want to expose the attribute line number via reflection as well. See also https://externals.io/message/111915. Closes GH-6201.
Diffstat (limited to 'Zend/zend_compile.c')
-rw-r--r--Zend/zend_compile.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c
index ba6790a042..cc03a60e5f 100644
--- a/Zend/zend_compile.c
+++ b/Zend/zend_compile.c
@@ -6221,7 +6221,10 @@ static void zend_compile_attributes(HashTable **attributes, zend_ast *ast, uint3
zend_string *name = zend_resolve_class_name_ast(el->child[0]);
zend_ast_list *args = el->child[1] ? zend_ast_get_list(el->child[1]) : NULL;
- attr = zend_add_attribute(attributes, 0, offset, name, args ? args->children : 0);
+ uint32_t flags = (CG(active_op_array)->fn_flags & ZEND_ACC_STRICT_TYPES)
+ ? ZEND_ATTRIBUTE_STRICT_TYPES : 0;
+ attr = zend_add_attribute(
+ attributes, name, args ? args->children : 0, flags, offset, el->lineno);
zend_string_release(name);
/* Populate arguments */