Skip to content

Commit cfc148f

Browse files
committed
Fix enum case conflict in trait binding
1 parent fbd3017 commit cfc148f

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

Zend/tests/enum/gh21760.phpt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
--TEST--
2+
GH-21760 (Trait with class constant name conflict against enum case causes SEGV)
3+
--FILE--
4+
<?php
5+
6+
trait X {
7+
public const Up = 1;
8+
}
9+
10+
enum Direction {
11+
use X;
12+
13+
case Up;
14+
case Down;
15+
}
16+
17+
?>
18+
--EXPECTF--
19+
Fatal error: Direction and X define the same constant (Up) in the composition of Direction. However, the definition differs and is considered incompatible. Class was composed in %s on line %d

Zend/zend_inheritance.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2770,6 +2770,11 @@ static bool do_trait_constant_check(
27702770

27712771
zend_class_constant *existing_constant = Z_PTR_P(zv);
27722772

2773+
if (UNEXPECTED(ZEND_CLASS_CONST_FLAGS(existing_constant) & ZEND_CLASS_CONST_IS_CASE)) {
2774+
emit_incompatible_trait_constant_error(ce, existing_constant, trait_constant, name, traits, current_trait);
2775+
return false;
2776+
}
2777+
27732778
if ((ZEND_CLASS_CONST_FLAGS(trait_constant) & flags_mask) != (ZEND_CLASS_CONST_FLAGS(existing_constant) & flags_mask)) {
27742779
emit_incompatible_trait_constant_error(ce, existing_constant, trait_constant, name, traits, current_trait);
27752780
return false;

0 commit comments

Comments
 (0)