Skip to content

Commit 4837bdb

Browse files
committed
Merge branch 'PHP-5.4' into PHP-5.5
* PHP-5.4: Fixed bug #63976 (Parent class incorrectly using child constant in class property) Conflicts: NEWS
2 parents 960d5be + 7b0993b commit 4837bdb

File tree

2 files changed

+56
-2
lines changed

2 files changed

+56
-2
lines changed

Zend/tests/bug63976.phpt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
--TEST--
2+
Bug #63976 (Parent class incorrectly using child constant in class property)
3+
--FILE--
4+
<?php
5+
if (1) {
6+
class Foo {
7+
const TABLE = "foo";
8+
public $table = self::TABLE;
9+
}
10+
}
11+
if (1) {
12+
class Bar extends Foo {
13+
const TABLE = "bar";
14+
}
15+
}
16+
$bar = new Bar();
17+
var_dump($bar->table);
18+
?>
19+
--EXPECT--
20+
string(3) "foo"

Zend/zend_API.c

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,6 +1051,40 @@ ZEND_API void zend_merge_properties(zval *obj, HashTable *properties, int destro
10511051
}
10521052
/* }}} */
10531053

1054+
static int zval_update_class_constant(zval **pp, int is_static, int offset TSRMLS_DC) /* {{{ */
1055+
{
1056+
if ((Z_TYPE_PP(pp) & IS_CONSTANT_TYPE_MASK) == IS_CONSTANT ||
1057+
(Z_TYPE_PP(pp) & IS_CONSTANT_TYPE_MASK) == IS_CONSTANT_ARRAY) {
1058+
zend_class_entry **scope = EG(in_execution)?&EG(scope):&CG(active_class_entry);
1059+
1060+
if ((*scope)->parent) {
1061+
zend_class_entry *ce = *scope;
1062+
HashPosition pos;
1063+
zend_property_info *prop_info;
1064+
1065+
do {
1066+
for (zend_hash_internal_pointer_reset_ex(&ce->properties_info, &pos);
1067+
zend_hash_get_current_data_ex(&ce->properties_info, (void **) &prop_info, &pos) == SUCCESS;
1068+
zend_hash_move_forward_ex(&ce->properties_info, &pos)) {
1069+
if (is_static == ((prop_info->flags & ZEND_ACC_STATIC) != 0) &&
1070+
offset == prop_info->offset) {
1071+
zend_class_entry *old_scope = *scope;
1072+
*scope = prop_info->ce;
1073+
int ret = zval_update_constant(pp, (void*)1 TSRMLS_CC);
1074+
*scope = old_scope;
1075+
return ret;
1076+
}
1077+
}
1078+
ce = ce->parent;
1079+
} while (ce);
1080+
1081+
}
1082+
return zval_update_constant(pp, (void*)1 TSRMLS_CC);
1083+
}
1084+
return 0;
1085+
}
1086+
/* }}} */
1087+
10541088
ZEND_API void zend_update_class_constants(zend_class_entry *class_type TSRMLS_DC) /* {{{ */
10551089
{
10561090
if ((class_type->ce_flags & ZEND_ACC_CONSTANTS_UPDATED) == 0 || (!CE_STATIC_MEMBERS(class_type) && class_type->default_static_members_count)) {
@@ -1063,7 +1097,7 @@ ZEND_API void zend_update_class_constants(zend_class_entry *class_type TSRMLS_DC
10631097

10641098
for (i = 0; i < class_type->default_properties_count; i++) {
10651099
if (class_type->default_properties_table[i]) {
1066-
zval_update_constant(&class_type->default_properties_table[i], (void**)1 TSRMLS_CC);
1100+
zval_update_class_constant(&class_type->default_properties_table[i], 0, i TSRMLS_CC);
10671101
}
10681102
}
10691103

@@ -1104,7 +1138,7 @@ ZEND_API void zend_update_class_constants(zend_class_entry *class_type TSRMLS_DC
11041138
}
11051139

11061140
for (i = 0; i < class_type->default_static_members_count; i++) {
1107-
zval_update_constant(&CE_STATIC_MEMBERS(class_type)[i], (void**)1 TSRMLS_CC);
1141+
zval_update_class_constant(&CE_STATIC_MEMBERS(class_type)[i], 1, i TSRMLS_CC);
11081142
}
11091143

11101144
*scope = old_scope;

0 commit comments

Comments
 (0)