From: Nikita Popov Date: Mon, 22 Sep 2014 22:40:17 +0000 (+0200) Subject: Test error conditions for ct class const refs X-Git-Tag: PRE_NATIVE_TLS_MERGE~158^2~58 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=51119054ffbb30d67c0afa77d5830f190b1fdc14;p=php Test error conditions for ct class const refs And fix a bug found while doing so... --- diff --git a/Zend/tests/constant_expressions_dynamic_class_name_error.phpt b/Zend/tests/constant_expressions_dynamic_class_name_error.phpt new file mode 100644 index 0000000000..3ce5844649 --- /dev/null +++ b/Zend/tests/constant_expressions_dynamic_class_name_error.phpt @@ -0,0 +1,11 @@ +--TEST-- +Dynamic class names can't be used in compile-time constant refs +--FILE-- + +--EXPECTF-- +Fatal error: Dynamic class names are not allowed in compile-time class constant references in %s on line %d diff --git a/Zend/tests/constant_expressions_static_class_name_error.phpt b/Zend/tests/constant_expressions_static_class_name_error.phpt new file mode 100644 index 0000000000..f03a88b87e --- /dev/null +++ b/Zend/tests/constant_expressions_static_class_name_error.phpt @@ -0,0 +1,10 @@ +--TEST-- +Cannot use static::FOO in constant expressions +--FILE-- + +--EXPECTF-- +Fatal error: "static::" is not allowed in compile-time constants in %s on line %d diff --git a/Zend/zend_ast.h b/Zend/zend_ast.h index 716b385210..db7b623d9f 100644 --- a/Zend/zend_ast.h +++ b/Zend/zend_ast.h @@ -220,7 +220,9 @@ static zend_always_inline zval *zend_ast_get_zval(zend_ast *ast) { return &((zend_ast_zval *) ast)->val; } static zend_always_inline zend_string *zend_ast_get_str(zend_ast *ast) { - return Z_STR_P(zend_ast_get_zval(ast)); + zval *zv = zend_ast_get_zval(ast); + ZEND_ASSERT(Z_TYPE_P(zv) == IS_STRING); + return Z_STR_P(zv); } static zend_always_inline uint32_t zend_ast_get_num_children(zend_ast *ast) { diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index a7e12fe9a5..ca4aa695ad 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -5846,7 +5846,7 @@ void zend_compile_const_expr_class_const(zend_ast **ast_ptr TSRMLS_DC) /* {{{ */ zend_ast *ast = *ast_ptr; zend_ast *class_ast = ast->child[0]; zend_ast *const_ast = ast->child[1]; - zend_string *class_name = zend_ast_get_str(class_ast); + zend_string *class_name; zend_string *const_name = zend_ast_get_str(const_ast); zval result; int fetch_type; @@ -5856,6 +5856,7 @@ void zend_compile_const_expr_class_const(zend_ast **ast_ptr TSRMLS_DC) /* {{{ */ "Dynamic class names are not allowed in compile-time class constant references"); } + class_name = zend_ast_get_str(class_ast); fetch_type = zend_get_class_fetch_type(class_name); if (ZEND_FETCH_CLASS_STATIC == fetch_type) {