]> granicus.if.org Git - php/commitdiff
Fixed bug #42819 (namespaces in indexes of constant arrays)
authorDmitry Stogov <dmitry@php.net>
Tue, 2 Oct 2007 08:27:19 +0000 (08:27 +0000)
committerDmitry Stogov <dmitry@php.net>
Tue, 2 Oct 2007 08:27:19 +0000 (08:27 +0000)
Zend/tests/bug42819.phpt [new file with mode: 0755]
Zend/zend.h
Zend/zend_compile.c
Zend/zend_execute_API.c
Zend/zend_vm_def.h
Zend/zend_vm_execute.h

diff --git a/Zend/tests/bug42819.phpt b/Zend/tests/bug42819.phpt
new file mode 100755 (executable)
index 0000000..812c26b
--- /dev/null
@@ -0,0 +1,282 @@
+--TEST--
+Bug #42819 (namespaces in indexes of constant arrays)
+--FILE--
+<?php
+namespace foo;
+
+const C = "foo::C\n";
+const I = 11;
+
+class foo {
+       const C = "foo::foo::C\n";
+       const I = 22;
+       const C1 = C;
+       const C2 = foo::C;
+       const C3 = foo::foo::C;
+       const C4 = ::foo::C;
+       const C5 = ::foo::foo::C;
+       const C6 = ArrayObject::STD_PROP_LIST;
+       const C7 = E_ERROR;
+}
+
+class bar1 {
+       static $a1 = array(I => 0);
+       static $a2 = array(foo::I => 0);
+       static $a3 = array(foo::foo::I => 0);
+       static $a4 = array(::foo::I => 0);
+       static $a5 = array(::foo::foo::I => 0);
+       static $a6 = array(ArrayObject::STD_PROP_LIST => 0);
+       static $a7 = array(E_ERROR => 0);
+}
+
+class bar2 {
+       static $a1 = array(I => I);
+       static $a2 = array(foo::I => I);
+       static $a3 = array(foo::foo::I => I);
+       static $a4 = array(::foo::I => I);
+       static $a5 = array(::foo::foo::I => I);
+       static $a6 = array(ArrayObject::STD_PROP_LIST => I);
+       static $a7 = array(E_ERROR => I);
+}
+
+class bar3 {
+       static $a1 = array(I => foo::I);
+       static $a2 = array(foo::I => foo::I);
+       static $a3 = array(foo::foo::I => foo::I);
+       static $a4 = array(::foo::I => foo::I);
+       static $a5 = array(::foo::foo::I => foo::I);
+       static $a6 = array(ArrayObject::STD_PROP_LIST => foo::I);
+       static $a7 = array(E_ERROR => foo::I);
+}
+
+class bar4 {
+       static $a1 = array(I => ArrayObject::STD_PROP_LIST);
+       static $a2 = array(foo::I => ArrayObject::STD_PROP_LIST);
+       static $a3 = array(foo::foo::I => ArrayObject::STD_PROP_LIST);
+       static $a4 = array(::foo::I => ArrayObject::STD_PROP_LIST);
+       static $a5 = array(::foo::foo::I => ArrayObject::STD_PROP_LIST);
+       static $a6 = array(ArrayObject::STD_PROP_LIST => ArrayObject::STD_PROP_LIST);
+       static $a7 = array(E_ERROR => ArrayObject::STD_PROP_LIST);
+}
+
+class bar5 {
+       static $a1 = array(I => E_ERROR);
+       static $a2 = array(foo::I => E_ERROR);
+       static $a3 = array(foo::foo::I => E_ERROR);
+       static $a4 = array(::foo::I => E_ERROR);
+       static $a5 = array(::foo::foo::I => E_ERROR);
+       static $a6 = array(ArrayObject::STD_PROP_LIST => E_ERROR);
+       static $a7 = array(E_ERROR => E_ERROR);
+}
+
+echo C;
+echo foo::C;
+echo foo::foo::C;
+echo ::foo::C;
+echo ::foo::foo::C;
+echo ArrayObject::STD_PROP_LIST . "\n";
+echo E_ERROR . "\n";
+
+echo foo::foo::C1;
+echo foo::foo::C2;
+echo foo::foo::C3;
+echo foo::foo::C4;
+echo foo::foo::C5;
+echo foo::foo::C6 . "\n";
+echo foo::foo::C7 . "\n";
+
+print_r(bar1::$a1);
+print_r(bar1::$a2);
+print_r(bar1::$a3);
+print_r(bar1::$a4);
+print_r(bar1::$a5);
+print_r(bar1::$a6);
+print_r(bar1::$a7);
+
+print_r(bar2::$a1);
+print_r(bar2::$a2);
+print_r(bar2::$a3);
+print_r(bar2::$a4);
+print_r(bar2::$a5);
+print_r(bar2::$a6);
+print_r(bar2::$a7);
+
+print_r(bar3::$a1);
+print_r(bar3::$a2);
+print_r(bar3::$a3);
+print_r(bar3::$a4);
+print_r(bar3::$a5);
+print_r(bar3::$a6);
+print_r(bar3::$a7);
+
+print_r(bar4::$a1);
+print_r(bar4::$a2);
+print_r(bar4::$a3);
+print_r(bar4::$a4);
+print_r(bar4::$a5);
+print_r(bar4::$a6);
+print_r(bar4::$a7);
+
+print_r(bar5::$a1);
+print_r(bar5::$a2);
+print_r(bar5::$a3);
+print_r(bar5::$a4);
+print_r(bar5::$a5);
+print_r(bar5::$a6);
+print_r(bar5::$a7);
+?>
+--EXPECT--
+foo::C
+foo::C
+foo::foo::C
+foo::C
+foo::foo::C
+1
+1
+foo::C
+foo::C
+foo::foo::C
+foo::C
+foo::foo::C
+1
+1
+Array
+(
+    [11] => 0
+)
+Array
+(
+    [11] => 0
+)
+Array
+(
+    [22] => 0
+)
+Array
+(
+    [11] => 0
+)
+Array
+(
+    [22] => 0
+)
+Array
+(
+    [1] => 0
+)
+Array
+(
+    [1] => 0
+)
+Array
+(
+    [11] => 11
+)
+Array
+(
+    [11] => 11
+)
+Array
+(
+    [22] => 11
+)
+Array
+(
+    [11] => 11
+)
+Array
+(
+    [22] => 11
+)
+Array
+(
+    [1] => 11
+)
+Array
+(
+    [1] => 11
+)
+Array
+(
+    [11] => 11
+)
+Array
+(
+    [11] => 11
+)
+Array
+(
+    [22] => 11
+)
+Array
+(
+    [11] => 11
+)
+Array
+(
+    [22] => 11
+)
+Array
+(
+    [1] => 11
+)
+Array
+(
+    [1] => 11
+)
+Array
+(
+    [11] => 1
+)
+Array
+(
+    [11] => 1
+)
+Array
+(
+    [22] => 1
+)
+Array
+(
+    [11] => 1
+)
+Array
+(
+    [22] => 1
+)
+Array
+(
+    [1] => 1
+)
+Array
+(
+    [1] => 1
+)
+Array
+(
+    [11] => 1
+)
+Array
+(
+    [11] => 1
+)
+Array
+(
+    [22] => 1
+)
+Array
+(
+    [11] => 1
+)
+Array
+(
+    [22] => 1
+)
+Array
+(
+    [1] => 1
+)
+Array
+(
+    [1] => 1
+)
index de96c1e3b17d0c63628a571f347dcdae2721c81f..8fb4a2d41f5ea432775267ff84836db55a732337 100644 (file)
@@ -336,6 +336,7 @@ struct _zval_struct {
        zend_uint refcount;
        zend_uchar type;        /* active type */
        zend_uchar is_ref;
+       zend_uchar idx_type;    /* type of element's index in constant array */
 };
 
 
index 0dc9a2282f4a9c7b3d0c56e68711779ef49a2a84..a99c7d218ac7da98cca1deee3c1f1781860579cd 100644 (file)
@@ -3943,6 +3943,7 @@ void zend_do_add_static_array_element(znode *result, znode *offset, znode *expr)
                        case IS_CONSTANT:
                                /* Ugly hack to denote that this value has a constant index */
                                Z_TYPE_P(element) |= IS_CONSTANT_INDEX;
+                               element->idx_type = Z_TYPE(offset->u.constant);
                                /* break missing intentionally */
                                utype = UG(unicode)?IS_UNICODE:IS_STRING;
                        case IS_STRING:
index 3e2ba09ed3835ce9b9fb214d49f19195a69a7b12..55a7351ab0557a7695e826fbd45af3785a043be0 100644 (file)
@@ -550,7 +550,7 @@ ZEND_API int zval_update_constant_ex(zval **pp, void *arg, zend_class_entry *sco
                                zend_hash_move_forward(Z_ARRVAL_P(p));
                                continue;
                        }
-                       if (!zend_u_get_constant_ex(ZEND_STR_TYPE, str_index, str_index_len-1, &const_value, scope, 0 TSRMLS_CC)) {
+                       if (!zend_u_get_constant_ex(ZEND_STR_TYPE, str_index, str_index_len-1, &const_value, scope, (*element)->idx_type TSRMLS_CC)) {
                                if ((UG(unicode) && (colon.u = u_memchr(str_index.u, ':', str_index_len-1)) && colon.u[1] == ':') ||
                                    (!UG(unicode) && (colon.s = memchr(str_index.s, ':', str_index_len-1)) && colon.s[1] == ':')) {
                                        zend_error(E_ERROR, "Undefined class constant '%v'", str_index);
index 8fa69d1f6b2aeaa15eff8959e1d22df7d6d97f20..033c9943e4bdb39a804990b92e13277a98a7dcdf 100644 (file)
@@ -2759,7 +2759,7 @@ ZEND_VM_HANDLER(99, ZEND_FETCH_CONSTANT, VAR|UNUSED|CONST, CONST)
 
                if (zend_u_hash_find(&ce->constants_table, Z_TYPE(opline->op2.u.constant), Z_UNIVAL(opline->op2.u.constant), Z_UNILEN(opline->op2.u.constant)+1, (void **) &value) == SUCCESS) {
                        if (Z_TYPE_PP(value) == IS_CONSTANT_ARRAY ||
-                           Z_TYPE_PP(value) == IS_CONSTANT) {
+                           (Z_TYPE_PP(value) & IS_CONSTANT_TYPE_MASK) == IS_CONSTANT) {
                                zend_class_entry *old_scope = EG(scope);
 
                                EG(scope) = ce;
index 6fc4f2910a75db304b92be439a8aa1a3f69745f6..6e3c5c0097d752220c9e2ac831a16f4697e57e0f 100644 (file)
@@ -2703,7 +2703,7 @@ static int ZEND_FETCH_CONSTANT_SPEC_CONST_CONST_HANDLER(ZEND_OPCODE_HANDLER_ARGS
 
                if (zend_u_hash_find(&ce->constants_table, Z_TYPE(opline->op2.u.constant), Z_UNIVAL(opline->op2.u.constant), Z_UNILEN(opline->op2.u.constant)+1, (void **) &value) == SUCCESS) {
                        if (Z_TYPE_PP(value) == IS_CONSTANT_ARRAY ||
-                           Z_TYPE_PP(value) == IS_CONSTANT) {
+                           (Z_TYPE_PP(value) & IS_CONSTANT_TYPE_MASK) == IS_CONSTANT) {
                                zend_class_entry *old_scope = EG(scope);
 
                                EG(scope) = ce;
@@ -10201,7 +10201,7 @@ static int ZEND_FETCH_CONSTANT_SPEC_VAR_CONST_HANDLER(ZEND_OPCODE_HANDLER_ARGS)
 
                if (zend_u_hash_find(&ce->constants_table, Z_TYPE(opline->op2.u.constant), Z_UNIVAL(opline->op2.u.constant), Z_UNILEN(opline->op2.u.constant)+1, (void **) &value) == SUCCESS) {
                        if (Z_TYPE_PP(value) == IS_CONSTANT_ARRAY ||
-                           Z_TYPE_PP(value) == IS_CONSTANT) {
+                           (Z_TYPE_PP(value) & IS_CONSTANT_TYPE_MASK) == IS_CONSTANT) {
                                zend_class_entry *old_scope = EG(scope);
 
                                EG(scope) = ce;
@@ -16957,7 +16957,7 @@ static int ZEND_FETCH_CONSTANT_SPEC_UNUSED_CONST_HANDLER(ZEND_OPCODE_HANDLER_ARG
 
                if (zend_u_hash_find(&ce->constants_table, Z_TYPE(opline->op2.u.constant), Z_UNIVAL(opline->op2.u.constant), Z_UNILEN(opline->op2.u.constant)+1, (void **) &value) == SUCCESS) {
                        if (Z_TYPE_PP(value) == IS_CONSTANT_ARRAY ||
-                           Z_TYPE_PP(value) == IS_CONSTANT) {
+                           (Z_TYPE_PP(value) & IS_CONSTANT_TYPE_MASK) == IS_CONSTANT) {
                                zend_class_entry *old_scope = EG(scope);
 
                                EG(scope) = ce;