@@ -1394,6 +1394,9 @@ static inheritance_status class_constant_types_compatible(const zend_class_const
1394
1394
return zend_perform_covariant_type_check (child -> ce , child -> type , parent -> ce , parent -> type );
1395
1395
}
1396
1396
1397
+ static bool do_inherit_constant_check (
1398
+ zend_class_entry * ce , zend_class_constant * parent_constant , zend_string * name );
1399
+
1397
1400
static void do_inherit_class_constant (zend_string * name , zend_class_constant * parent_const , zend_class_entry * ce ) /* {{{ */
1398
1401
{
1399
1402
zval * zv = zend_hash_find_known_hash (& ce -> constants_table , name );
@@ -1411,21 +1414,8 @@ static void do_inherit_class_constant(zend_string *name, zend_class_constant *pa
1411
1414
);
1412
1415
}
1413
1416
1414
- if (UNEXPECTED ((ZEND_CLASS_CONST_FLAGS (parent_const ) & ZEND_ACC_FINAL ))) {
1415
- zend_error_noreturn (
1416
- E_COMPILE_ERROR , "%s::%s cannot override final constant %s::%s" ,
1417
- ZSTR_VAL (ce -> name ), ZSTR_VAL (name ), ZSTR_VAL (parent_const -> ce -> name ), ZSTR_VAL (name )
1418
- );
1419
- }
1420
-
1421
- if (!(ZEND_CLASS_CONST_FLAGS (parent_const ) & ZEND_ACC_PRIVATE ) && UNEXPECTED (ZEND_TYPE_IS_SET (parent_const -> type ))) {
1422
- inheritance_status status = class_constant_types_compatible (parent_const , c );
1423
- if (status == INHERITANCE_ERROR ) {
1424
- emit_incompatible_class_constant_error (c , parent_const , name );
1425
- } else if (status == INHERITANCE_UNRESOLVED ) {
1426
- add_class_constant_compatibility_obligation (ce , c , parent_const , name );
1427
- }
1428
- }
1417
+ bool inherit = do_inherit_constant_check (ce , parent_const , name );
1418
+ ZEND_ASSERT (!inherit );
1429
1419
} else if (!(ZEND_CLASS_CONST_FLAGS (parent_const ) & ZEND_ACC_PRIVATE )) {
1430
1420
if (Z_TYPE (parent_const -> value ) == IS_CONSTANT_AST ) {
1431
1421
ce -> ce_flags &= ~ZEND_ACC_CONSTANTS_UPDATED ;
@@ -1718,6 +1708,7 @@ static zend_always_inline bool check_trait_property_or_constant_value_compatibil
1718
1708
}
1719
1709
/* }}} */
1720
1710
1711
+ /** @return bool Returns true if the class constant should be inherited, i.e. whether it doesn't already exist. */
1721
1712
static bool do_inherit_constant_check (
1722
1713
zend_class_entry * ce , zend_class_constant * parent_constant , zend_string * name
1723
1714
) {
@@ -1726,23 +1717,33 @@ static bool do_inherit_constant_check(
1726
1717
return true;
1727
1718
}
1728
1719
1729
- zend_class_constant * old_constant = Z_PTR_P (zv );
1730
- if (parent_constant -> ce != old_constant -> ce && (ZEND_CLASS_CONST_FLAGS (parent_constant ) & ZEND_ACC_FINAL )) {
1720
+ zend_class_constant * child_constant = Z_PTR_P (zv );
1721
+ if (parent_constant -> ce != child_constant -> ce && (ZEND_CLASS_CONST_FLAGS (parent_constant ) & ZEND_ACC_FINAL )) {
1731
1722
zend_error_noreturn (E_COMPILE_ERROR , "%s::%s cannot override final constant %s::%s" ,
1732
- ZSTR_VAL (old_constant -> ce -> name ), ZSTR_VAL (name ),
1723
+ ZSTR_VAL (child_constant -> ce -> name ), ZSTR_VAL (name ),
1733
1724
ZSTR_VAL (parent_constant -> ce -> name ), ZSTR_VAL (name )
1734
1725
);
1735
1726
}
1736
1727
1737
- if (old_constant -> ce != parent_constant -> ce && old_constant -> ce != ce ) {
1728
+ if (child_constant -> ce != parent_constant -> ce && child_constant -> ce != ce ) {
1738
1729
zend_error_noreturn (E_COMPILE_ERROR ,
1739
1730
"%s %s inherits both %s::%s and %s::%s, which is ambiguous" ,
1740
1731
zend_get_object_type_uc (ce ),
1741
1732
ZSTR_VAL (ce -> name ),
1742
- ZSTR_VAL (old_constant -> ce -> name ), ZSTR_VAL (name ),
1733
+ ZSTR_VAL (child_constant -> ce -> name ), ZSTR_VAL (name ),
1743
1734
ZSTR_VAL (parent_constant -> ce -> name ), ZSTR_VAL (name ));
1744
1735
}
1745
1736
1737
+
1738
+ if (!(ZEND_CLASS_CONST_FLAGS (parent_constant ) & ZEND_ACC_PRIVATE ) && UNEXPECTED (ZEND_TYPE_IS_SET (parent_constant -> type ))) {
1739
+ inheritance_status status = class_constant_types_compatible (parent_constant , child_constant );
1740
+ if (status == INHERITANCE_ERROR ) {
1741
+ emit_incompatible_class_constant_error (child_constant , parent_constant , name );
1742
+ } else if (status == INHERITANCE_UNRESOLVED ) {
1743
+ add_class_constant_compatibility_obligation (ce , child_constant , parent_constant , name );
1744
+ }
1745
+ }
1746
+
1746
1747
return false;
1747
1748
}
1748
1749
/* }}} */
0 commit comments