]> granicus.if.org Git - php/commitdiff
Test error conditions for ct class const refs
authorNikita Popov <nikic@php.net>
Mon, 22 Sep 2014 22:40:17 +0000 (00:40 +0200)
committerNikita Popov <nikic@php.net>
Mon, 22 Sep 2014 22:40:17 +0000 (00:40 +0200)
And fix a bug found while doing so...

Zend/tests/constant_expressions_dynamic_class_name_error.phpt [new file with mode: 0644]
Zend/tests/constant_expressions_static_class_name_error.phpt [new file with mode: 0644]
Zend/zend_ast.h
Zend/zend_compile.c

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 (file)
index 0000000..3ce5844
--- /dev/null
@@ -0,0 +1,11 @@
+--TEST--
+Dynamic class names can't be used in compile-time constant refs
+--FILE--
+<?php
+
+$foo = 'test';
+const C = $foo::BAR;
+
+?>
+--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 (file)
index 0000000..f03a88b
--- /dev/null
@@ -0,0 +1,10 @@
+--TEST--
+Cannot use static::FOO in constant expressions
+--FILE--
+<?php
+
+const C = static::FOO;
+
+?>
+--EXPECTF--
+Fatal error: "static::" is not allowed in compile-time constants in %s on line %d
index 716b38521017223453d1162b4bf256abfec73f0c..db7b623d9f493bb7bb30d01910febee240f11c13 100644 (file)
@@ -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) {
index a7e12fe9a5b5d63342063478887e5adc96eb2eed..ca4aa695ad866f3fce4e13681a22c585f423ca32 100644 (file)
@@ -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) {