Skip to content

Commit 3f3e652

Browse files
committed
Change the location of the error handling to reduce surprises.
1 parent 5a2dea2 commit 3f3e652

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

Zend/zend_inheritance.c

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2234,26 +2234,25 @@ static bool do_trait_constant_check(zend_class_entry *ce, zend_class_constant *t
22342234

22352235
zval *zv = zend_hash_find_known_hash(&ce->constants_table, name);
22362236
if (zv == NULL) {
2237-
// No existing constant of the same name, so this one can be added
2237+
/* No existing constant of the same name, so this one can be added */
22382238
return true;
22392239
}
22402240

22412241
zend_class_constant *existing_constant = Z_PTR_P(zv);
22422242

2243-
if ((ZEND_CLASS_CONST_FLAGS(trait_constant) & flags_mask) == (ZEND_CLASS_CONST_FLAGS(existing_constant) & flags_mask)) {
2244-
if (check_trait_property_or_constant_value_compatibility(ce, &trait_constant->value, &existing_constant->value)) {
2245-
// There is an existing constant which is compatible with the new one, so no need to add it
2246-
return false;
2247-
}
2243+
if ((ZEND_CLASS_CONST_FLAGS(trait_constant) & flags_mask) != (ZEND_CLASS_CONST_FLAGS(existing_constant) & flags_mask) ||
2244+
!check_trait_property_or_constant_value_compatibility(ce, &trait_constant->value, &existing_constant->value)) {
2245+
/* There is an existing constant of the same name, and it conflicts with the new one, so let's throw a fatal error */
2246+
zend_error_noreturn(E_COMPILE_ERROR,
2247+
"%s and %s define the same constant (%s) in the composition of %s. However, the definition differs and is considered incompatible. Class was composed",
2248+
ZSTR_VAL(find_first_constant_definition(ce, traits, current_trait, name, existing_constant->ce)->name),
2249+
ZSTR_VAL(trait_constant->ce->name),
2250+
ZSTR_VAL(name),
2251+
ZSTR_VAL(ce->name));
22482252
}
22492253

2250-
// There is an existing constant of the same name, and it conflicts with the new one, so let's throw a fatal error
2251-
zend_error_noreturn(E_COMPILE_ERROR,
2252-
"%s and %s define the same constant (%s) in the composition of %s. However, the definition differs and is considered incompatible. Class was composed",
2253-
ZSTR_VAL(find_first_constant_definition(ce, traits, current_trait, name, existing_constant->ce)->name),
2254-
ZSTR_VAL(trait_constant->ce->name),
2255-
ZSTR_VAL(name),
2256-
ZSTR_VAL(ce->name));
2254+
/* There is an existing constant which is compatible with the new one, so no need to add it */
2255+
return false;
22572256
}
22582257
/* }}} */
22592258

0 commit comments

Comments
 (0)