Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 10 additions & 0 deletions Zend/tests/enum/extending-builtin-error.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
--TEST--
Error message when extending enums (GH-16315) (extending built in enum)
--FILE--
<?php

class Demo extends RoundingMode {}

?>
--EXPECTF--
Fatal error: Class Demo cannot extend enum RoundingMode in %s on line 3
12 changes: 12 additions & 0 deletions Zend/tests/enum/extending-user-error.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
--TEST--
Error message when extending enums (GH-16315) (extending userland enum)
--FILE--
<?php

enum MyEnum {}

class Demo extends MyEnum {}

?>
--EXPECTF--
Fatal error: Class Demo cannot extend enum MyEnum in %s on line 5
8 changes: 4 additions & 4 deletions Zend/tests/enum/final.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ Enum is final

enum Foo {}

class Bar extends Foo {}

$final = new ReflectionClass(Foo::class)->isFinal();
var_dump( $final );
?>
--EXPECTF--
Fatal error: Class Bar cannot extend final class Foo in %s on line %d
--EXPECT--
bool(true)
7 changes: 6 additions & 1 deletion Zend/zend_inheritance.c
Original file line number Diff line number Diff line change
Expand Up @@ -1757,7 +1757,12 @@ ZEND_API void zend_do_inheritance_ex(zend_class_entry *ce, zend_class_entry *par
if (UNEXPECTED(!(parent_ce->ce_flags & ZEND_ACC_INTERFACE))) {
zend_error_noreturn(E_COMPILE_ERROR, "Interface %s cannot extend class %s", ZSTR_VAL(ce->name), ZSTR_VAL(parent_ce->name));
}
} else if (UNEXPECTED(parent_ce->ce_flags & (ZEND_ACC_INTERFACE|ZEND_ACC_TRAIT|ZEND_ACC_FINAL))) {
} else if (UNEXPECTED(parent_ce->ce_flags & (ZEND_ACC_INTERFACE|ZEND_ACC_TRAIT|ZEND_ACC_FINAL|ZEND_ACC_ENUM))) {
/* Class must not extend an enum (GH-16315); check enums first since
enums are implemented as final classes */
if (parent_ce->ce_flags & ZEND_ACC_ENUM) {
zend_error_noreturn(E_COMPILE_ERROR, "Class %s cannot extend enum %s", ZSTR_VAL(ce->name), ZSTR_VAL(parent_ce->name));
}
/* Class must not extend a final class */
if (parent_ce->ce_flags & ZEND_ACC_FINAL) {
zend_error_noreturn(E_COMPILE_ERROR, "Class %s cannot extend final class %s", ZSTR_VAL(ce->name), ZSTR_VAL(parent_ce->name));
Expand Down
Loading