Skip to content

Commit 9b984f5

Browse files
authored
Enum error message consistency (php#9350)
1 parent 567213c commit 9b984f5

29 files changed

+184
-25
lines changed

Zend/tests/enum/__clone.phpt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
--TEST--
2+
Enum __clone
3+
--FILE--
4+
<?php
5+
6+
enum Foo {
7+
case Bar;
8+
9+
public function __clone() {
10+
}
11+
}
12+
13+
?>
14+
--EXPECTF--
15+
Fatal error: Enum Foo cannot include magic method __clone in %s on line %d

Zend/tests/enum/__debugInfo.phpt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
--TEST--
2+
Enum __debugInfo
3+
--FILE--
4+
<?php
5+
6+
enum Foo {
7+
case Bar;
8+
9+
public function __debugInfo(): array {
10+
return $this->cases();
11+
}
12+
}
13+
14+
?>
15+
--EXPECTF--
16+
Fatal error: Enum Foo cannot include magic method __debugInfo in %s on line %d

Zend/tests/enum/__get.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ enum Foo {
1414

1515
?>
1616
--EXPECTF--
17-
Fatal error: Enum may not include __get in %s on line %d
17+
Fatal error: Enum Foo cannot include magic method __get in %s on line %d

Zend/tests/enum/__isset.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ enum Foo {
1313

1414
?>
1515
--EXPECTF--
16-
Fatal error: Enum may not include __isset in %s on line %d
16+
Fatal error: Enum Foo cannot include magic method __isset in %s on line %d

Zend/tests/enum/__serialize.phpt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
--TEST--
2+
Enum __serialize
3+
--FILE--
4+
<?php
5+
6+
enum Foo {
7+
case Bar;
8+
9+
public function __serialize(): array {
10+
return $this->cases();
11+
}
12+
}
13+
14+
?>
15+
--EXPECTF--
16+
Fatal error: Enum Foo cannot include magic method __serialize in %s on line %d

Zend/tests/enum/__set.phpt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
--TEST--
2+
Enum __set
3+
--FILE--
4+
<?php
5+
6+
enum Foo {
7+
case Bar;
8+
9+
public function __set(string $name, mixed $value)
10+
{
11+
}
12+
}
13+
14+
?>
15+
--EXPECTF--
16+
Fatal error: Enum Foo cannot include magic method __set in %s on line %d

Zend/tests/enum/__set_state.phpt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
--TEST--
2+
Enum __set_state
3+
--FILE--
4+
<?php
5+
6+
enum Foo {
7+
case Bar;
8+
9+
public static function __set_state(array $properties): object {
10+
11+
}
12+
}
13+
14+
?>
15+
--EXPECTF--
16+
Fatal error: Enum Foo cannot include magic method __set_state in %s on line %d

Zend/tests/enum/__sleep.phpt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
--TEST--
2+
Enum __sleep
3+
--FILE--
4+
<?php
5+
6+
enum Foo {
7+
case Bar;
8+
9+
public function __sleep(): array {
10+
11+
}
12+
}
13+
14+
?>
15+
--EXPECTF--
16+
Fatal error: Enum Foo cannot include magic method __sleep in %s on line %d

Zend/tests/enum/__toString.phpt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
--TEST--
2+
Enum __toString
3+
--FILE--
4+
<?php
5+
6+
enum Foo {
7+
case Bar;
8+
9+
public function __toString(): string {
10+
return $this->name;
11+
}
12+
}
13+
14+
?>
15+
--EXPECTF--
16+
Fatal error: Enum Foo cannot include magic method __toString in %s on line %d

Zend/tests/enum/__unserialize.phpt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
--TEST--
2+
Enum __unserialize
3+
--FILE--
4+
<?php
5+
6+
enum Foo {
7+
case Bar;
8+
9+
public function __unserialize(array $data) {
10+
11+
}
12+
}
13+
14+
?>
15+
--EXPECTF--
16+
Fatal error: Enum Foo cannot include magic method __unserialize in %s on line %d

Zend/tests/enum/__unset.phpt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
--TEST--
2+
Enum __unset
3+
--FILE--
4+
<?php
5+
6+
enum Foo {
7+
case Bar;
8+
9+
public function __unset($property) {
10+
return;
11+
}
12+
}
13+
14+
?>
15+
--EXPECTF--
16+
Fatal error: Enum Foo cannot include magic method __unset in %s on line %d

Zend/tests/enum/__wakeup.phpt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
--TEST--
2+
Enum __wakeup
3+
--FILE--
4+
<?php
5+
6+
enum Foo {
7+
case Bar;
8+
9+
public function __wakeup() {
10+
11+
}
12+
}
13+
14+
?>
15+
--EXPECTF--
16+
Fatal error: Enum Foo cannot include magic method __wakeup in %s on line %d

Zend/tests/enum/backed-from-invalid-int.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ try {
1616

1717
?>
1818
--EXPECT--
19-
2 is not a valid backing value for enum "Foo"
19+
2 is not a valid backing value for enum Foo

Zend/tests/enum/backed-from-invalid-string.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ try {
1818

1919
?>
2020
--EXPECT--
21-
"A" is not a valid backing value for enum "Suit"
21+
"A" is not a valid backing value for enum Suit

Zend/tests/enum/backed-from-invalid-type.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,5 @@ try {
3030

3131
?>
3232
--EXPECT--
33-
"42" is not a valid backing value for enum "Suit"
33+
"42" is not a valid backing value for enum Suit
3434
Foo::from(): Argument #1 ($value) must be of type int, string given

Zend/tests/enum/internal_enums.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,9 @@ enum(ZendTestIntEnum::Foo)
8686
enum(ZendTestIntEnum::Foo)
8787
enum(ZendTestIntEnum::Foo)
8888
enum(ZendTestIntEnum::Foo)
89-
ValueError: 2 is not a valid backing value for enum "ZendTestIntEnum"
89+
ValueError: 2 is not a valid backing value for enum ZendTestIntEnum
9090
NULL
91-
ValueError: 2 is not a valid backing value for enum "ZendTestIntEnum"
91+
ValueError: 2 is not a valid backing value for enum ZendTestIntEnum
9292
NULL
9393
enum(ZendTestIntEnum::Baz)
9494
enum(ZendTestIntEnum::Baz)

Zend/tests/enum/no-constructors.phpt

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

1010
?>
1111
--EXPECTF--
12-
Fatal error: Enum may not include __construct in %s on line %d
12+
Fatal error: Enum Foo cannot include magic method __construct in %s on line %d

Zend/tests/enum/no-destruct.phpt

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

1010
?>
1111
--EXPECTF--
12-
Fatal error: Enum may not include __destruct in %s on line %d
12+
Fatal error: Enum Foo cannot include magic method __destruct in %s on line %d

Zend/tests/enum/no-implement-serializable-indirect.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@ var_dump(unserialize(serialize(Foo::Bar)));
2323
--EXPECTF--
2424
Deprecated: %s implements the Serializable interface, which is deprecated. Implement __serialize() and __unserialize() instead (or in addition, if support for old PHP versions is necessary) in %s on line %d
2525

26-
Fatal error: Enums may not implement the Serializable interface in %s on line %d
26+
Fatal error: Enum Foo cannot implement the Serializable interface in %s on line %d

Zend/tests/enum/no-implement-serializable.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ var_dump(unserialize(serialize(Foo::Bar)));
2121
--EXPECTF--
2222
Deprecated: %s implements the Serializable interface, which is deprecated. Implement __serialize() and __unserialize() instead (or in addition, if support for old PHP versions is necessary) in %s on line %d
2323

24-
Fatal error: Enums may not implement the Serializable interface in %s on line %d
24+
Fatal error: Enum Foo cannot implement the Serializable interface in %s on line %d

Zend/tests/enum/no-name-property.phpt

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

1010
?>
1111
--EXPECTF--
12-
Fatal error: Enums may not include properties in %s on line %d
12+
Fatal error: Enum Foo cannot include properties in %s on line %d

Zend/tests/enum/no-properties.phpt

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

1010
?>
1111
--EXPECTF--
12-
Fatal error: Enums may not include properties in %s on line %d
12+
Fatal error: Enum Foo cannot include properties in %s on line %d

Zend/tests/enum/no-static-properties.phpt

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

1010
?>
1111
--EXPECTF--
12-
Fatal error: Enums may not include properties in %s on line %d
12+
Fatal error: Enum Foo cannot include properties in %s on line %d

Zend/tests/enum/no-value-property.phpt

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

1010
?>
1111
--EXPECTF--
12-
Fatal error: Enums may not include properties in %s on line %d
12+
Fatal error: Enum Foo cannot include properties in %s on line %d

Zend/tests/enum/traits-no-__construct.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ var_dump(Bar::Baz);
1818

1919
?>
2020
--EXPECTF--
21-
Fatal error: Enum may not include __construct in %s on line %d
21+
Fatal error: Enum Bar cannot include magic method __construct in %s on line %d

Zend/tests/enum/traits-no-forbidden-methods.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ enum Suit {
1818

1919
?>
2020
--EXPECTF--
21-
Fatal error: Enum may not include __construct in %s on line %d
21+
Fatal error: Enum Suit cannot include magic method __construct in %s on line %d

Zend/tests/enum/traits-no-properties.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@ enum Suit {
2222

2323
?>
2424
--EXPECTF--
25-
Fatal error: Enum "Suit" may not include properties in %s on line %d
25+
Fatal error: Enum Suit cannot include properties in %s on line %d

Zend/zend_compile.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7407,7 +7407,7 @@ static void zend_compile_prop_decl(zend_ast *ast, zend_ast *type_ast, uint32_t f
74077407
}
74087408

74097409
if (ce->ce_flags & ZEND_ACC_ENUM) {
7410-
zend_error_noreturn(E_COMPILE_ERROR, "Enums may not include properties");
7410+
zend_error_noreturn(E_COMPILE_ERROR, "Enum %s cannot include properties", ZSTR_VAL(ce->name));
74117411
}
74127412

74137413
if (flags & ZEND_ACC_ABSTRACT) {

Zend/zend_enum.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
#define ZEND_ENUM_DISALLOW_MAGIC_METHOD(propertyName, methodName) \
2929
do { \
3030
if (ce->propertyName) { \
31-
zend_error_noreturn(E_COMPILE_ERROR, "Enum may not include %s", methodName); \
31+
zend_error_noreturn(E_COMPILE_ERROR, "Enum %s cannot include magic method %s", ZSTR_VAL(ce->name), methodName); \
3232
} \
3333
} while (0);
3434

@@ -67,7 +67,7 @@ static void zend_verify_enum_properties(zend_class_entry *ce)
6767
continue;
6868
}
6969
// FIXME: File/line number for traits?
70-
zend_error_noreturn(E_COMPILE_ERROR, "Enum \"%s\" may not include properties",
70+
zend_error_noreturn(E_COMPILE_ERROR, "Enum %s cannot include properties",
7171
ZSTR_VAL(ce->name));
7272
} ZEND_HASH_FOREACH_END();
7373
}
@@ -99,7 +99,7 @@ static void zend_verify_enum_magic_methods(zend_class_entry *ce)
9999
const char *forbidden_method = forbidden_methods[i];
100100

101101
if (zend_hash_str_exists(&ce->function_table, forbidden_method, strlen(forbidden_method))) {
102-
zend_error_noreturn(E_COMPILE_ERROR, "Enum may not include magic method %s", forbidden_method);
102+
zend_error_noreturn(E_COMPILE_ERROR, "Enum %s cannot include magic method %s", ZSTR_VAL(ce->name), forbidden_method);
103103
}
104104
}
105105
}
@@ -108,7 +108,7 @@ static void zend_verify_enum_interfaces(zend_class_entry *ce)
108108
{
109109
if (zend_class_implements_interface(ce, zend_ce_serializable)) {
110110
zend_error_noreturn(E_COMPILE_ERROR,
111-
"Enums may not implement the Serializable interface");
111+
"Enum %s cannot implement the Serializable interface", ZSTR_VAL(ce->name));
112112
}
113113
}
114114

@@ -307,10 +307,10 @@ ZEND_API zend_result zend_enum_get_case_by_value(zend_object **result, zend_clas
307307
}
308308

309309
if (ce->enum_backing_type == IS_LONG) {
310-
zend_value_error(ZEND_LONG_FMT " is not a valid backing value for enum \"%s\"", long_key, ZSTR_VAL(ce->name));
310+
zend_value_error(ZEND_LONG_FMT " is not a valid backing value for enum %s", long_key, ZSTR_VAL(ce->name));
311311
} else {
312312
ZEND_ASSERT(ce->enum_backing_type == IS_STRING);
313-
zend_value_error("\"%s\" is not a valid backing value for enum \"%s\"", ZSTR_VAL(string_key), ZSTR_VAL(ce->name));
313+
zend_value_error("\"%s\" is not a valid backing value for enum %s", ZSTR_VAL(string_key), ZSTR_VAL(ce->name));
314314
}
315315
return FAILURE;
316316
}

0 commit comments

Comments
 (0)