diff options
author | Dmitry Stogov <dmitry@php.net> | 2007-06-13 14:50:13 +0000 |
---|---|---|
committer | Dmitry Stogov <dmitry@php.net> | 2007-06-13 14:50:13 +0000 |
commit | 28bc39500a7609531f5277c0bbf40eb273ff321a (patch) | |
tree | 78205ef34496300047d05d97d1095c8db8e9a82a | |
parent | f018ec9024e1455c13c7acac612a91eea923c936 (diff) | |
download | php-git-28bc39500a7609531f5277c0bbf40eb273ff321a.tar.gz |
Fixed some class constant issues related to bug #41633
-rwxr-xr-x | Zend/tests/bug41633_1.phpt | 12 | ||||
-rwxr-xr-x | Zend/tests/bug41633_2.phpt | 11 | ||||
-rw-r--r-- | Zend/zend_execute_API.c | 7 | ||||
-rw-r--r-- | Zend/zend_vm_def.h | 4 | ||||
-rw-r--r-- | Zend/zend_vm_execute.h | 8 |
5 files changed, 42 insertions, 0 deletions
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-- +<?php +class Foo { + const A = self::B; + const B = "ok"; +} +echo Foo::A."\n"; +?> +--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-- +<?php +class Foo { + const A = self::B; +} +echo Foo::A."\n"; +?> +--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 { |