]> granicus.if.org Git - php/commitdiff
Fixed bug #63976 (Parent class incorrectly using child constant in class property)
authorDmitry Stogov <dmitry@zend.com>
Tue, 19 Mar 2013 12:59:01 +0000 (16:59 +0400)
committerDmitry Stogov <dmitry@zend.com>
Tue, 19 Mar 2013 12:59:01 +0000 (16:59 +0400)
NEWS
Zend/tests/bug63976.phpt [new file with mode: 0644]
Zend/zend_API.c

diff --git a/NEWS b/NEWS
index 3c6579d028f84886cbd062f6d837f15ac09e94bd..ca51fc3930307ef1e26dda60b86b80fae0b6b13f 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -6,6 +6,8 @@ PHP                                                                        NEWS
     (Dmitry)
   . Fixed bug #64370 (microtime(true) less than $_SERVER['REQUEST_TIME_FLOAT']).
     (Anatol)
+  . Fixed bug #63976 (Parent class incorrectly using child constant in class
+    property). (Dmitry)
   . Fixed bug #62343 (Show class_alias In get_declared_classes()) (Dmitry)
 
 - PCRE:
diff --git a/Zend/tests/bug63976.phpt b/Zend/tests/bug63976.phpt
new file mode 100644 (file)
index 0000000..0ac09d9
--- /dev/null
@@ -0,0 +1,20 @@
+--TEST--
+Bug #63976 (Parent class incorrectly using child constant in class property)
+--FILE--
+<?php
+if (1) {
+  class Foo {
+    const TABLE = "foo";
+    public $table = self::TABLE;
+  }
+}
+if (1) {
+  class Bar extends Foo {
+    const TABLE = "bar";
+  }
+}
+$bar = new Bar();
+var_dump($bar->table);
+?>
+--EXPECT--
+string(3) "foo"
index eec4ab0bb1529c31825af0482a8f6cda0325b988..b9e97cb342bdcb5a19ead2a0610e3716f32b2b3f 100644 (file)
@@ -1022,6 +1022,40 @@ ZEND_API void zend_merge_properties(zval *obj, HashTable *properties, int destro
 }
 /* }}} */
 
+static int zval_update_class_constant(zval **pp, int is_static, int offset TSRMLS_DC) /* {{{ */
+{
+       if ((Z_TYPE_PP(pp) & IS_CONSTANT_TYPE_MASK) == IS_CONSTANT ||
+           (Z_TYPE_PP(pp) & IS_CONSTANT_TYPE_MASK) == IS_CONSTANT_ARRAY) {         
+               zend_class_entry **scope = EG(in_execution)?&EG(scope):&CG(active_class_entry);
+
+               if ((*scope)->parent) {
+                       zend_class_entry *ce = *scope;
+                       HashPosition pos;
+                       zend_property_info *prop_info;
+
+                       do {
+                               for (zend_hash_internal_pointer_reset_ex(&ce->properties_info, &pos);
+                                    zend_hash_get_current_data_ex(&ce->properties_info, (void **) &prop_info, &pos) == SUCCESS;
+                                    zend_hash_move_forward_ex(&ce->properties_info, &pos)) {
+                                       if (is_static == ((prop_info->flags & ZEND_ACC_STATIC) != 0) &&
+                                           offset == prop_info->offset) {
+                                               zend_class_entry *old_scope = *scope;
+                                               *scope = prop_info->ce;
+                                               int ret = zval_update_constant(pp, (void*)1 TSRMLS_CC);
+                                               *scope = old_scope;
+                                               return ret;
+                                       }
+                               }                               
+                               ce = ce->parent;
+                       } while (ce);
+                       
+               }
+               return zval_update_constant(pp, (void*)1 TSRMLS_CC);
+       }
+       return 0;
+}
+/* }}} */
+
 ZEND_API void zend_update_class_constants(zend_class_entry *class_type TSRMLS_DC) /* {{{ */
 {
        if ((class_type->ce_flags & ZEND_ACC_CONSTANTS_UPDATED) == 0 || (!CE_STATIC_MEMBERS(class_type) && class_type->default_static_members_count)) {
@@ -1034,7 +1068,7 @@ ZEND_API void zend_update_class_constants(zend_class_entry *class_type TSRMLS_DC
 
                for (i = 0; i < class_type->default_properties_count; i++) {
                        if (class_type->default_properties_table[i]) {
-                               zval_update_constant(&class_type->default_properties_table[i], (void**)1 TSRMLS_CC);
+                               zval_update_class_constant(&class_type->default_properties_table[i], 0, i TSRMLS_CC);
                        }
                }
 
@@ -1075,7 +1109,7 @@ ZEND_API void zend_update_class_constants(zend_class_entry *class_type TSRMLS_DC
                }
 
                for (i = 0; i < class_type->default_static_members_count; i++) {
-                       zval_update_constant(&CE_STATIC_MEMBERS(class_type)[i], (void**)1 TSRMLS_CC);
+                       zval_update_class_constant(&CE_STATIC_MEMBERS(class_type)[i], 1, i TSRMLS_CC);
                }
 
                *scope = old_scope;