Commit:    7b0993bfb4b19bb160a72310b907c4fc12a5bef9
Author:    Dmitry Stogov <dmi...@zend.com>         Tue, 19 Mar 2013 16:59:01 
+0400
Parents:   984561cfa81adfd893833bce506544349b04c803
Branches:  PHP-5.4 PHP-5.5 master

Link:       
http://git.php.net/?p=php-src.git;a=commitdiff;h=7b0993bfb4b19bb160a72310b907c4fc12a5bef9

Log:
Fixed bug #63976 (Parent class incorrectly using child constant in class 
property)

Bugs:
https://bugs.php.net/63976

Changed paths:
  M  NEWS
  A  Zend/tests/bug63976.phpt
  M  Zend/zend_API.c


Diff:
diff --git a/NEWS b/NEWS
index 3c6579d..ca51fc3 100644
--- 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
index 0000000..0ac09d9
--- /dev/null
+++ b/Zend/tests/bug63976.phpt
@@ -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"
diff --git a/Zend/zend_API.c b/Zend/zend_API.c
index eec4ab0..b9e97cb 100644
--- a/Zend/zend_API.c
+++ b/Zend/zend_API.c
@@ -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;


--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to