Skip to content

Commit b436ef4

Browse files
phpGH-15994: fix suggestion that anonymous classes be made abstract (phpGH-15995)
In the process, remove the (incorrect) assumption that any abstract method that needs to be implemented by a class that cannot itself be made abstract must be a private method - the existing test for an enum already showed that this was not the case.
1 parent 3b349db commit b436ef4

File tree

4 files changed

+17
-4
lines changed

4 files changed

+17
-4
lines changed

Zend/tests/anon/gh15994.phpt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
--TEST--
2+
Abstract function must be implemented
3+
--FILE--
4+
<?php
5+
6+
abstract class ParentClass {
7+
abstract public function f();
8+
}
9+
10+
$o = new class extends ParentClass {};
11+
?>
12+
--EXPECTF--
13+
Fatal error: Class ParentClass@anonymous must implement 1 abstract method (ParentClass::f) in %sgh15994.php on line 7

Zend/tests/gh7792_1.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ enum B implements A {}
1111

1212
?>
1313
--EXPECTF--
14-
Fatal error: Enum B must implement 1 abstract private method (A::a) in %s on line %d
14+
Fatal error: Enum B must implement 1 abstract method (A::a) in %s on line %d

Zend/tests/traits/abstract_method_6.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ class D extends C {
1717

1818
?>
1919
--EXPECTF--
20-
Fatal error: Class C must implement 1 abstract private method (C::method) in %s on line %d
20+
Fatal error: Class C must implement 1 abstract method (C::method) in %s on line %d

Zend/zend_inheritance.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2981,7 +2981,7 @@ void zend_verify_abstract_class(zend_class_entry *ce) /* {{{ */
29812981
const zend_function *func;
29822982
zend_abstract_info ai;
29832983
bool is_explicit_abstract = (ce->ce_flags & ZEND_ACC_EXPLICIT_ABSTRACT_CLASS) != 0;
2984-
bool can_be_abstract = (ce->ce_flags & ZEND_ACC_ENUM) == 0;
2984+
bool can_be_abstract = (ce->ce_flags & (ZEND_ACC_ENUM|ZEND_ACC_ANON_CLASS)) == 0;
29852985
memset(&ai, 0, sizeof(ai));
29862986

29872987
ZEND_HASH_MAP_FOREACH_PTR(&ce->function_table, func) {
@@ -3022,7 +3022,7 @@ void zend_verify_abstract_class(zend_class_entry *ce) /* {{{ */
30223022
);
30233023
} else {
30243024
zend_error_noreturn(E_ERROR,
3025-
"%s %s must implement %d abstract private method%s (" MAX_ABSTRACT_INFO_FMT MAX_ABSTRACT_INFO_FMT MAX_ABSTRACT_INFO_FMT ")",
3025+
"%s %s must implement %d abstract method%s (" MAX_ABSTRACT_INFO_FMT MAX_ABSTRACT_INFO_FMT MAX_ABSTRACT_INFO_FMT ")",
30263026
zend_get_object_type_uc(ce),
30273027
ZSTR_VAL(ce->name), ai.cnt,
30283028
ai.cnt > 1 ? "s" : "",

0 commit comments

Comments
 (0)