]> granicus.if.org Git - php/commitdiff
Fixed some class constant issues related to bug #41633
authorDmitry Stogov <dmitry@php.net>
Wed, 13 Jun 2007 14:50:13 +0000 (14:50 +0000)
committerDmitry Stogov <dmitry@php.net>
Wed, 13 Jun 2007 14:50:13 +0000 (14:50 +0000)
Zend/tests/bug41633_1.phpt [new file with mode: 0755]
Zend/tests/bug41633_2.phpt [new file with mode: 0755]
Zend/zend_execute_API.c
Zend/zend_vm_def.h
Zend/zend_vm_execute.h

diff --git a/Zend/tests/bug41633_1.phpt b/Zend/tests/bug41633_1.phpt
new file mode 100755 (executable)
index 0000000..1c1d552
--- /dev/null
@@ -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 (executable)
index 0000000..3deb451
--- /dev/null
@@ -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
index e0b44c6587dcb224811f0d722dceeb46cfe11b71..f3a123e390c557b9ff7379ee72444416d3a85583 100644 (file)
@@ -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;
index 7ca9377fc1f02add7d934b24ca4a9a1bc578c084..42c4d2dfe3d3ca1b0a3c90473614e6c21de6b5a8 100644 (file)
@@ -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 {
index 0307dae99307fa33c19b9898d1e729cd65d7c99c..f2b7ead360b58b00c118dbdfe873b61e227f7eda 100644 (file)
@@ -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 {