From: Dmitry Stogov Date: Wed, 13 Jun 2007 14:50:13 +0000 (+0000) Subject: Fixed some class constant issues related to bug #41633 X-Git-Tag: php-5.2.4RC1~357 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=28bc39500a7609531f5277c0bbf40eb273ff321a;p=php Fixed some class constant issues related to bug #41633 --- diff --git a/Zend/tests/bug41633_1.phpt b/Zend/tests/bug41633_1.phpt new file mode 100755 index 0000000000..1c1d552dd7 --- /dev/null +++ b/Zend/tests/bug41633_1.phpt @@ -0,0 +1,12 @@ +--TEST-- +Bug #41633.1 (self:: doesn't work for constants) +--FILE-- + +--EXPECT-- +ok diff --git a/Zend/tests/bug41633_2.phpt b/Zend/tests/bug41633_2.phpt new file mode 100755 index 0000000000..3deb4516ac --- /dev/null +++ b/Zend/tests/bug41633_2.phpt @@ -0,0 +1,11 @@ +--TEST-- +Bug #41633.2 (Undefined class constants must not be substituted by strings) +--FILE-- + +--EXPECTF-- +Fatal error: Undefined class constant 'self::B' in %sbug41633_2.php on line 5 diff --git a/Zend/zend_execute_API.c b/Zend/zend_execute_API.c index e0b44c6587..f3a123e390 100644 --- a/Zend/zend_execute_API.c +++ b/Zend/zend_execute_API.c @@ -453,6 +453,7 @@ ZEND_API int zval_update_constant_ex(zval **pp, void *arg, zend_class_entry *sco zval *p = *pp; zend_bool inline_change = (zend_bool) (zend_uintptr_t) arg; zval const_value; + char *colon; if (Z_TYPE_P(p) == IS_CONSTANT) { int refcount; @@ -465,6 +466,9 @@ ZEND_API int zval_update_constant_ex(zval **pp, void *arg, zend_class_entry *sco is_ref = p->is_ref; if (!zend_get_constant_ex(p->value.str.val, p->value.str.len, &const_value, scope TSRMLS_CC)) { + if ((colon = memchr(Z_STRVAL_P(p), ':', Z_STRLEN_P(p))) && colon[1] == ':') { + zend_error(E_ERROR, "Undefined class constant '%s'", Z_STRVAL_P(p)); + } zend_error(E_NOTICE, "Use of undefined constant %s - assumed '%s'", p->value.str.val, p->value.str.val); @@ -504,6 +508,9 @@ ZEND_API int zval_update_constant_ex(zval **pp, void *arg, zend_class_entry *sco continue; } if (!zend_get_constant_ex(str_index, str_index_len-1, &const_value, scope TSRMLS_CC)) { + if ((colon = memchr(str_index, ':', str_index_len-1)) && colon[1] == ':') { + zend_error(E_ERROR, "Undefined class constant '%s'", str_index); + } zend_error(E_NOTICE, "Use of undefined constant %s - assumed '%s'", str_index, str_index); zend_hash_move_forward(Z_ARRVAL_P(p)); continue; diff --git a/Zend/zend_vm_def.h b/Zend/zend_vm_def.h index 7ca9377fc1..42c4d2dfe3 100644 --- a/Zend/zend_vm_def.h +++ b/Zend/zend_vm_def.h @@ -2613,7 +2613,11 @@ ZEND_VM_HANDLER(99, ZEND_FETCH_CONSTANT, CONST|UNUSED, CONST) ce = EX_T(opline->op1.u.var).class_entry; if (zend_hash_find(&ce->constants_table, opline->op2.u.constant.value.str.val, opline->op2.u.constant.value.str.len+1, (void **) &value) == SUCCESS) { + zend_class_entry *old_scope = EG(scope); + + EG(scope) = ce; zval_update_constant(value, (void *) 1 TSRMLS_CC); + EG(scope) = old_scope; EX_T(opline->result.u.var).tmp_var = **value; zval_copy_ctor(&EX_T(opline->result.u.var).tmp_var); } else { diff --git a/Zend/zend_vm_execute.h b/Zend/zend_vm_execute.h index 0307dae993..f2b7ead360 100644 --- a/Zend/zend_vm_execute.h +++ b/Zend/zend_vm_execute.h @@ -2694,7 +2694,11 @@ static int ZEND_FETCH_CONSTANT_SPEC_CONST_CONST_HANDLER(ZEND_OPCODE_HANDLER_ARGS ce = EX_T(opline->op1.u.var).class_entry; if (zend_hash_find(&ce->constants_table, opline->op2.u.constant.value.str.val, opline->op2.u.constant.value.str.len+1, (void **) &value) == SUCCESS) { + zend_class_entry *old_scope = EG(scope); + + EG(scope) = ce; zval_update_constant(value, (void *) 1 TSRMLS_CC); + EG(scope) = old_scope; EX_T(opline->result.u.var).tmp_var = **value; zval_copy_ctor(&EX_T(opline->result.u.var).tmp_var); } else { @@ -15486,7 +15490,11 @@ static int ZEND_FETCH_CONSTANT_SPEC_UNUSED_CONST_HANDLER(ZEND_OPCODE_HANDLER_ARG ce = EX_T(opline->op1.u.var).class_entry; if (zend_hash_find(&ce->constants_table, opline->op2.u.constant.value.str.val, opline->op2.u.constant.value.str.len+1, (void **) &value) == SUCCESS) { + zend_class_entry *old_scope = EG(scope); + + EG(scope) = ce; zval_update_constant(value, (void *) 1 TSRMLS_CC); + EG(scope) = old_scope; EX_T(opline->result.u.var).tmp_var = **value; zval_copy_ctor(&EX_T(opline->result.u.var).tmp_var); } else {