Skip to content

GH-15992: fix error message for single abstract method not implemented #15993

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
2 changes: 1 addition & 1 deletion Zend/tests/bug69084.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ $b->main();

?>
--EXPECTF--
Fatal error: Class Bar contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (Bar::doOtherStuff) in %s on line %d
Fatal error: Class Bar contains 1 abstract method and must therefore be declared abstract or implement the remaining method (Bar::doOtherStuff) in %s on line %d
2 changes: 1 addition & 1 deletion Zend/tests/errmsg_018.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ class test {
echo "Done\n";
?>
--EXPECTF--
Fatal error: Class test contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (test::foo) in %s on line %d
Fatal error: Class test contains 1 abstract method and must therefore be declared abstract or implement the remaining method (test::foo) in %s on line %d
2 changes: 1 addition & 1 deletion Zend/tests/property_hooks/abstract_get_set_readonly.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ class C extends P {
}
?>
--EXPECTF--
Fatal error: Class C contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (P::$prop::set) in %s on line %d
Fatal error: Class C contains 1 abstract method and must therefore be declared abstract or implement the remaining method (P::$prop::set) in %s on line %d
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ class Test {

?>
--EXPECTF--
Fatal error: Class Test contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (Test::$prop::get) in %s on line %d
Fatal error: Class Test contains 1 abstract method and must therefore be declared abstract or implement the remaining method (Test::$prop::get) in %s on line %d
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ class B extends A {}

?>
--EXPECTF--
Fatal error: Class B contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (A::$prop::get) in %s on line %d
Fatal error: Class B contains 1 abstract method and must therefore be declared abstract or implement the remaining method (A::$prop::get) in %s on line %d
2 changes: 1 addition & 1 deletion Zend/tests/property_hooks/invalid_abstract_indirect.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ class B extends A {

?>
--EXPECTF--
Fatal error: Class B contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (A::$prop::get) in %s on line %d
Fatal error: Class B contains 1 abstract method and must therefore be declared abstract or implement the remaining method (A::$prop::get) in %s on line %d
2 changes: 1 addition & 1 deletion Zend/tests/property_hooks/invalid_abstract_indirect_2.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ class B extends A {

?>
--EXPECTF--
Fatal error: Class B contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (A::$prop::get) in %s on line %d
Fatal error: Class B contains 1 abstract method and must therefore be declared abstract or implement the remaining method (A::$prop::get) in %s on line %d
2 changes: 1 addition & 1 deletion Zend/tests/traits/bugs/abstract-methods01.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ $test = new TraitsTest();
$test->hello();
?>
--EXPECTF--
Fatal error: Class %s contains %d abstract method and must therefore be declared abstract or implement the remaining methods (%s) in %s on line %d
Fatal error: Class %s contains %d abstract method and must therefore be declared abstract or implement the remaining method (%s) in %s on line %d
2 changes: 1 addition & 1 deletion Zend/tests/traits/interface_002.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ new bar;

?>
--EXPECTF--
Fatal error: Class bar contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (baz::abc) in %s on line %d
Fatal error: Class bar contains 1 abstract method and must therefore be declared abstract or implement the remaining method (baz::abc) in %s on line %d
30 changes: 21 additions & 9 deletions Zend/zend_inheritance.c
Original file line number Diff line number Diff line change
Expand Up @@ -3009,16 +3009,28 @@ void zend_verify_abstract_class(zend_class_entry *ce) /* {{{ */
}

if (ai.cnt) {
zend_error_noreturn(E_ERROR, !is_explicit_abstract && can_be_abstract
? "%s %s contains %d abstract method%s and must therefore be declared abstract or implement the remaining methods (" MAX_ABSTRACT_INFO_FMT MAX_ABSTRACT_INFO_FMT MAX_ABSTRACT_INFO_FMT ")"
: "%s %s must implement %d abstract private 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" : "",
DISPLAY_ABSTRACT_FN(0),
DISPLAY_ABSTRACT_FN(1),
DISPLAY_ABSTRACT_FN(2)
if (!is_explicit_abstract && can_be_abstract) {
zend_error_noreturn(E_ERROR,
"%s %s contains %d abstract method%s and must therefore be declared abstract or implement the remaining 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" : "",
ai.cnt > 1 ? "s" : "",
DISPLAY_ABSTRACT_FN(0),
DISPLAY_ABSTRACT_FN(1),
DISPLAY_ABSTRACT_FN(2)
);
} 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 ")",
zend_get_object_type_uc(ce),
ZSTR_VAL(ce->name), ai.cnt,
ai.cnt > 1 ? "s" : "",
DISPLAY_ABSTRACT_FN(0),
DISPLAY_ABSTRACT_FN(1),
DISPLAY_ABSTRACT_FN(2)
);
}
} else {
/* now everything should be fine and an added ZEND_ACC_IMPLICIT_ABSTRACT_CLASS should be removed */
ce->ce_flags &= ~ZEND_ACC_IMPLICIT_ABSTRACT_CLASS;
Expand Down
2 changes: 1 addition & 1 deletion tests/classes/abstract_by_interface_001.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ class Fails extends Root implements MyInterface {
object(Leaf)#%d (0) {
}

Fatal error: Class Fails contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (MyInterface::MyInterfaceFunc) in %sabstract_by_interface_001.php on line %d
Fatal error: Class Fails contains 1 abstract method and must therefore be declared abstract or implement the remaining method (MyInterface::MyInterfaceFunc) in %sabstract_by_interface_001.php on line %d
2 changes: 1 addition & 1 deletion tests/classes/abstract_by_interface_002.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ class Fails extends Root implements MyInterface {
object(Leaf)#%d (0) {
}

Fatal error: Class Fails contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (MyInterface::MyInterfaceFunc) in %sabstract_by_interface_002.php on line %d
Fatal error: Class Fails contains 1 abstract method and must therefore be declared abstract or implement the remaining method (MyInterface::MyInterfaceFunc) in %sabstract_by_interface_002.php on line %d
2 changes: 1 addition & 1 deletion tests/classes/abstract_derived.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ class derived extends base {
?>
===DONE===
--EXPECTF--
Fatal error: Class derived contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (derived::show) in %sabstract_derived.php on line %d
Fatal error: Class derived contains 1 abstract method and must therefore be declared abstract or implement the remaining method (derived::show) in %sabstract_derived.php on line %d
2 changes: 1 addition & 1 deletion tests/classes/abstract_not_declared.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ class fail {
echo "Done\n"; // shouldn't be displayed
?>
--EXPECTF--
Fatal error: Class fail contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (fail::show) in %s on line %d
Fatal error: Class fail contains 1 abstract method and must therefore be declared abstract or implement the remaining method (fail::show) in %s on line %d
2 changes: 1 addition & 1 deletion tests/classes/abstract_redeclare.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ class fail extends pass {
echo "Done\n"; // Shouldn't be displayed
?>
--EXPECTF--
Fatal error: Class fail contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (fail::show) in %sabstract_redeclare.php on line %d
Fatal error: Class fail contains 1 abstract method and must therefore be declared abstract or implement the remaining method (fail::show) in %sabstract_redeclare.php on line %d
2 changes: 1 addition & 1 deletion tests/classes/abstract_static.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ echo "Done\n"; // shouldn't be displayed
--EXPECTF--
Call to function show()

Fatal error: Class fail contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (fail::func) in %sabstract_static.php(%d) : eval()'d code on line %d
Fatal error: Class fail contains 1 abstract method and must therefore be declared abstract or implement the remaining method (fail::func) in %sabstract_static.php(%d) : eval()'d code on line %d
2 changes: 1 addition & 1 deletion tests/classes/interface_must_be_implemented.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ class derived_a implements if_a {

?>
--EXPECTF--
Fatal error: Class derived_a contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (if_a::f_a) in %s on line %d
Fatal error: Class derived_a contains 1 abstract method and must therefore be declared abstract or implement the remaining method (if_a::f_a) in %s on line %d
2 changes: 1 addition & 1 deletion tests/classes/interfaces_002.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ echo "Message: " . $foo->getMessage() . "\n";
?>
===DONE===
--EXPECTF--
Fatal error: Class Exception_foo contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (ThrowableInterface::getErrno) in %s on line %d
Fatal error: Class Exception_foo contains 1 abstract method and must therefore be declared abstract or implement the remaining method (ThrowableInterface::getErrno) in %s on line %d
Loading