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

This commit is contained in:
Dmitry Stogov 2013-03-19 16:59:01 +04:00
parent 984561cfa8
commit 7b0993bfb4
3 changed files with 58 additions and 2 deletions

2
NEWS
View File

@ -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:

20
Zend/tests/bug63976.phpt Normal file
View File

@ -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"

View 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;