Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions Zend/tests/enum/gh21760.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
--TEST--
GH-21760 (Trait with class constant name conflict against enum case causes SEGV)
--FILE--
<?php

trait X {
public const Up = 1;
}

enum Direction {
use X;

case Up;
case Down;
}

?>
--EXPECTF--
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
5 changes: 5 additions & 0 deletions Zend/zend_inheritance.c
Original file line number Diff line number Diff line change
Expand Up @@ -2770,6 +2770,11 @@ static bool do_trait_constant_check(

zend_class_constant *existing_constant = Z_PTR_P(zv);

if (UNEXPECTED(ZEND_CLASS_CONST_FLAGS(existing_constant) & ZEND_CLASS_CONST_IS_CASE)) {
emit_incompatible_trait_constant_error(ce, existing_constant, trait_constant, name, traits, current_trait);
Comment thread
prateekbhujel marked this conversation as resolved.
Outdated
return false;
}

if ((ZEND_CLASS_CONST_FLAGS(trait_constant) & flags_mask) != (ZEND_CLASS_CONST_FLAGS(existing_constant) & flags_mask)) {
emit_incompatible_trait_constant_error(ce, existing_constant, trait_constant, name, traits, current_trait);
return false;
Expand Down
Loading