From 1f09a6b35993663f941025a21227fd54a7b7ad28 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Thu, 31 Jul 2008 14:27:43 +0000 Subject: [PATCH] Fixed constant substitution in constant expression context --- Zend/zend_compile.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index 13edf258c4..69dbd7f109 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -3759,7 +3759,7 @@ void zend_do_end_new_object(znode *result, znode *new_token, znode *argument_lis *result = CG(active_op_array)->opcodes[new_token->u.opline_num].result; } -static zend_constant* zend_get_ct_const(zval *const_name TSRMLS_DC) /* {{{ */ +static zend_constant* zend_get_ct_const(zval *const_name, int mode TSRMLS_DC) /* {{{ */ { zend_constant *c = NULL; @@ -3778,7 +3778,8 @@ static zend_constant* zend_get_ct_const(zval *const_name TSRMLS_DC) /* {{{ */ if (c->flags & CONST_CT_SUBST) { return c; } - if ((c->flags & CONST_PERSISTENT) && + if (mode == ZEND_RT && + (c->flags & CONST_PERSISTENT) && !CG(current_namespace) && !(CG(compiler_options) & ZEND_COMPILE_NO_CONSTANT_SUBSTITUTION) && Z_TYPE(c->value) != IS_CONSTANT && @@ -3789,9 +3790,9 @@ static zend_constant* zend_get_ct_const(zval *const_name TSRMLS_DC) /* {{{ */ } /* }}} */ -static int zend_constant_ct_subst(znode *result, zval *const_name TSRMLS_DC) /* {{{ */ +static int zend_constant_ct_subst(znode *result, zval *const_name, int mode TSRMLS_DC) /* {{{ */ { - zend_constant *c = zend_get_ct_const(const_name TSRMLS_CC); + zend_constant *c = zend_get_ct_const(const_name, mode TSRMLS_CC); if (c) { zval_dtor(const_name); @@ -3834,7 +3835,7 @@ void zend_do_fetch_constant(znode *result, znode *constant_container, znode *con zend_do_build_full_name(NULL, constant_container, constant_name TSRMLS_CC); *result = *constant_container; result->u.constant.type = IS_CONSTANT | fetch_type; - } else if (fetch_type || !zend_constant_ct_subst(result, &constant_name->u.constant TSRMLS_CC)) { + } else if (fetch_type || !zend_constant_ct_subst(result, &constant_name->u.constant, ZEND_CT TSRMLS_CC)) { if (check_namespace && CG(current_namespace)) { /* We assume we use constant from the current namespace if it is not prefixed. */ @@ -3851,7 +3852,7 @@ void zend_do_fetch_constant(znode *result, znode *constant_container, znode *con break; case ZEND_RT: if (constant_container || - !zend_constant_ct_subst(result, &constant_name->u.constant TSRMLS_CC)) { + !zend_constant_ct_subst(result, &constant_name->u.constant, ZEND_RT TSRMLS_CC)) { zend_op *opline; if (constant_container) { @@ -5152,14 +5153,12 @@ void zend_do_use(znode *ns_name, znode *new_name, int is_global TSRMLS_DC) /* {{ void zend_do_declare_constant(znode *name, znode *value TSRMLS_DC) /* {{{ */ { zend_op *opline; - zend_constant *c; if(Z_TYPE(value->u.constant) == IS_CONSTANT_ARRAY) { zend_error(E_COMPILE_ERROR, "Arrays are not allowed as constants"); } - c = zend_get_ct_const(&name->u.constant TSRMLS_CC); - if (c && (c->flags & CONST_CT_SUBST)) { + if (zend_get_ct_const(&name->u.constant, ZEND_CT TSRMLS_CC)) { zend_error(E_COMPILE_ERROR, "Cannot redeclare constant '%s'", Z_STRVAL(name->u.constant)); } -- 2.40.0