Skip to content

Commit 64bc13c

Browse files
Handle enums and improve condition
1 parent ca63778 commit 64bc13c

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

Zend/tests/enum/no-abstract.phpt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
--TEST--
2+
Compiler prevents `abstract` methods on enums classes (GH-16067)
3+
--FILE--
4+
<?php
5+
6+
enum Example {
7+
abstract public function foo();
8+
}
9+
10+
?>
11+
--EXPECTF--
12+
Fatal error: Enum Example cannot contain abstract method Example::foo in %s on line 4

Zend/zend_compile.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8068,14 +8068,15 @@ static zend_string *zend_begin_method_decl(zend_op_array *op_array, zend_string
80688068
}
80698069

80708070
if ((fn_flags & ZEND_ACC_ABSTRACT) &&
8071-
!(ce->ce_flags & (ZEND_ACC_EXPLICIT_ABSTRACT_CLASS|ZEND_ACC_TRAIT)) &&
8072-
!in_interface
8071+
!(ce->ce_flags & (ZEND_ACC_EXPLICIT_ABSTRACT_CLASS|ZEND_ACC_TRAIT|ZEND_ACC_INTERFACE))
80738072
) {
80748073
// Don't say that the class should be declared abstract if it is
8075-
// anonymous and can't be abstract
8074+
// anonymous or an enum and can't be abstract
80768075
const char *msg;
80778076
if (ce->ce_flags & ZEND_ACC_ANON_CLASS) {
80788077
msg = "Anonymous class %s cannot contain abstract method %s::%s";
8078+
} else if (ce->ce_flags & ZEND_ACC_ENUM) {
8079+
msg = "Enum %s cannot contain abstract method %s::%s";
80798080
} else {
80808081
msg = "Class %s contains abstract method %s::%s and must therefore be declared abstract";
80818082
}

0 commit comments

Comments
 (0)