Skip to content

GH-15994: fix suggestion that anonymous classes be made abstract #15995

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 25, 2024
Merged
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
13 changes: 13 additions & 0 deletions Zend/tests/anon/gh15994.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
--TEST--
Abstract function must be implemented
--FILE--
<?php

abstract class ParentClass {
abstract public function f();
}

$o = new class extends ParentClass {};
?>
--EXPECTF--
Fatal error: Class ParentClass@anonymous must implement 1 abstract method (ParentClass::f) in %sgh15994.php on line 7
2 changes: 1 addition & 1 deletion Zend/tests/gh7792_1.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ enum B implements A {}

?>
--EXPECTF--
Fatal error: Enum B must implement 1 abstract private method (A::a) in %s on line %d
Fatal error: Enum B must implement 1 abstract method (A::a) in %s on line %d
2 changes: 1 addition & 1 deletion Zend/tests/traits/abstract_method_6.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ class D extends C {

?>
--EXPECTF--
Fatal error: Class C must implement 1 abstract private method (C::method) in %s on line %d
Fatal error: Class C must implement 1 abstract method (C::method) in %s on line %d
4 changes: 2 additions & 2 deletions Zend/zend_inheritance.c
Original file line number Diff line number Diff line change
Expand Up @@ -2981,7 +2981,7 @@ void zend_verify_abstract_class(zend_class_entry *ce) /* {{{ */
const zend_function *func;
zend_abstract_info ai;
bool is_explicit_abstract = (ce->ce_flags & ZEND_ACC_EXPLICIT_ABSTRACT_CLASS) != 0;
bool can_be_abstract = (ce->ce_flags & ZEND_ACC_ENUM) == 0;
bool can_be_abstract = (ce->ce_flags & (ZEND_ACC_ENUM|ZEND_ACC_ANON_CLASS)) == 0;
memset(&ai, 0, sizeof(ai));

ZEND_HASH_MAP_FOREACH_PTR(&ce->function_table, func) {
Expand Down Expand Up @@ -3022,7 +3022,7 @@ void zend_verify_abstract_class(zend_class_entry *ce) /* {{{ */
);
} else {
zend_error_noreturn(E_ERROR,
"%s %s must implement %d abstract private method%s (" MAX_ABSTRACT_INFO_FMT MAX_ABSTRACT_INFO_FMT MAX_ABSTRACT_INFO_FMT ")",
"%s %s must implement %d abstract method%s (" MAX_ABSTRACT_INFO_FMT MAX_ABSTRACT_INFO_FMT MAX_ABSTRACT_INFO_FMT ")",
zend_get_object_type_uc(ce),
ZSTR_VAL(ce->name), ai.cnt,
ai.cnt > 1 ? "s" : "",
Expand Down
Loading