Skip to content

Commit 8dbb886

Browse files
committed
Improve error messages
1 parent 11e100f commit 8dbb886

10 files changed

+19
-29
lines changed

Zend/tests/abstract_implicit.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ class NotAbstract {
1616
}
1717
?>
1818
--EXPECTF--
19-
Fatal error: Class NotAbstract contains abstract method NotAbstract::bar and must therefore be declared abstract in %s on line %d
19+
Fatal error: Class NotAbstract declares abstract method bar() and must therefore be declared abstract in %s on line %d

Zend/tests/anon/gh16067.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ $c = new class {
88
}
99
?>
1010
--EXPECTF--
11-
Fatal error: Anonymous class class@anonymous cannot contain abstract method class@anonymous::f in %s on line 4
11+
Fatal error: Anonymous class method f() must not be abstract in %s on line 4

Zend/tests/enum/no-abstract.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ enum Example {
99

1010
?>
1111
--EXPECTF--
12-
Fatal error: Enum Example cannot contain abstract method Example::foo in %s on line 4
12+
Fatal error: Enum method Example::foo() must not be abstract in %s on line 4

Zend/tests/errmsg/errmsg_018.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ class test {
1010
echo "Done\n";
1111
?>
1212
--EXPECTF--
13-
Fatal error: Class test contains abstract method test::foo and must therefore be declared abstract in %s on line %d
13+
Fatal error: Class test declares abstract method foo() and must therefore be declared abstract in %s on line %d

Zend/zend_compile.c

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8067,26 +8067,20 @@ static zend_string *zend_begin_method_decl(zend_op_array *op_array, zend_string
80678067
zend_error(E_COMPILE_WARNING, "Private methods cannot be final as they are never overridden by other classes");
80688068
}
80698069

8070-
if ((fn_flags & ZEND_ACC_ABSTRACT) &&
8071-
!(ce->ce_flags & (ZEND_ACC_EXPLICIT_ABSTRACT_CLASS|ZEND_ACC_TRAIT|ZEND_ACC_INTERFACE))
8072-
) {
8070+
if ((fn_flags & ZEND_ACC_ABSTRACT)
8071+
&& !(ce->ce_flags & (ZEND_ACC_EXPLICIT_ABSTRACT_CLASS|ZEND_ACC_TRAIT))) {
80738072
// Don't say that the class should be declared abstract if it is
80748073
// anonymous or an enum and can't be abstract
8075-
const char *msg;
80768074
if (ce->ce_flags & ZEND_ACC_ANON_CLASS) {
8077-
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";
8075+
zend_error_noreturn(E_COMPILE_ERROR, "Anonymous class method %s() must not be abstract",
8076+
ZSTR_VAL(name));
8077+
} else if (ce->ce_flags & (ZEND_ACC_ENUM|ZEND_ACC_INTERFACE)) {
8078+
zend_error_noreturn(E_COMPILE_ERROR, "%s method %s::%s() must not be abstract",
8079+
zend_get_object_type_case(ce, true), ZSTR_VAL(ce->name), ZSTR_VAL(name));
80808080
} else {
8081-
msg = "Class %s contains abstract method %s::%s and must therefore be declared abstract";
8082-
}
8083-
zend_error_noreturn(
8084-
E_COMPILE_ERROR,
8085-
msg,
8086-
ZSTR_VAL(ce->name),
8087-
ZSTR_VAL(ce->name),
8088-
ZSTR_VAL(name)
8089-
);
8081+
zend_error_noreturn(E_COMPILE_ERROR, "Class %s declares abstract method %s() and must therefore be declared abstract",
8082+
ZSTR_VAL(ce->name), ZSTR_VAL(name));
8083+
}
80908084
}
80918085

80928086
if (in_interface) {
@@ -8098,10 +8092,6 @@ static zend_string *zend_begin_method_decl(zend_op_array *op_array, zend_string
80988092
zend_error_noreturn(E_COMPILE_ERROR, "Interface method "
80998093
"%s::%s() must not be final", ZSTR_VAL(ce->name), ZSTR_VAL(name));
81008094
}
8101-
if (fn_flags & ZEND_ACC_ABSTRACT) {
8102-
zend_error_noreturn(E_COMPILE_ERROR, "Interface method "
8103-
"%s::%s() must not be abstract", ZSTR_VAL(ce->name), ZSTR_VAL(name));
8104-
}
81058095
op_array->fn_flags |= ZEND_ACC_ABSTRACT;
81068096
}
81078097

tests/classes/abstract_derived.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ class derived extends base {
1313
?>
1414
===DONE===
1515
--EXPECTF--
16-
Fatal error: Class derived contains abstract method derived::show and must therefore be declared abstract in %sabstract_derived.php on line %d
16+
Fatal error: Class derived declares abstract method show() and must therefore be declared abstract in %sabstract_derived.php on line %d

tests/classes/abstract_not_declared.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ class fail {
1010
echo "Done\n"; // shouldn't be displayed
1111
?>
1212
--EXPECTF--
13-
Fatal error: Class fail contains abstract method fail::show and must therefore be declared abstract in %s on line %d
13+
Fatal error: Class fail declares abstract method show() and must therefore be declared abstract in %s on line %d

tests/classes/abstract_redeclare.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ class fail extends pass {
1616
echo "Done\n"; // Shouldn't be displayed
1717
?>
1818
--EXPECTF--
19-
Fatal error: Class fail contains abstract method fail::show and must therefore be declared abstract in %sabstract_redeclare.php on line %d
19+
Fatal error: Class fail declares abstract method show() and must therefore be declared abstract in %sabstract_redeclare.php on line %d

tests/classes/abstract_static.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,4 @@ echo "Done\n"; // shouldn't be displayed
3131
--EXPECTF--
3232
Call to function show()
3333

34-
Fatal error: Class fail contains abstract method fail::func and must therefore be declared abstract in %sabstract_static.php(%d) : eval()'d code on line %d
34+
Fatal error: Class fail declares abstract method func() and must therefore be declared abstract in %sabstract_static.php(%d) : eval()'d code on line %d

tests/classes/interface_method_private.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ ZE2 An interface method cannot be private
44
<?php
55

66
interface if_a {
7-
abstract private function err();
7+
private function err();
88
}
99

1010
?>

0 commit comments

Comments
 (0)