From 9b984f52ea3f532f3f842dff930fc263985bdfcd Mon Sep 17 00:00:00 2001 From: Ollie Read Date: Tue, 23 Aug 2022 12:32:34 +0100 Subject: [PATCH] Enum error message consistency (#9350) --- Zend/tests/enum/__clone.phpt | 15 +++++++++++++++ Zend/tests/enum/__debugInfo.phpt | 16 ++++++++++++++++ Zend/tests/enum/__get.phpt | 2 +- Zend/tests/enum/__isset.phpt | 2 +- Zend/tests/enum/__serialize.phpt | 16 ++++++++++++++++ Zend/tests/enum/__set.phpt | 16 ++++++++++++++++ Zend/tests/enum/__set_state.phpt | 16 ++++++++++++++++ Zend/tests/enum/__sleep.phpt | 16 ++++++++++++++++ Zend/tests/enum/__toString.phpt | 16 ++++++++++++++++ Zend/tests/enum/__unserialize.phpt | 16 ++++++++++++++++ Zend/tests/enum/__unset.phpt | 16 ++++++++++++++++ Zend/tests/enum/__wakeup.phpt | 16 ++++++++++++++++ Zend/tests/enum/backed-from-invalid-int.phpt | 2 +- Zend/tests/enum/backed-from-invalid-string.phpt | 2 +- Zend/tests/enum/backed-from-invalid-type.phpt | 2 +- Zend/tests/enum/internal_enums.phpt | 4 ++-- Zend/tests/enum/no-constructors.phpt | 2 +- Zend/tests/enum/no-destruct.phpt | 2 +- .../enum/no-implement-serializable-indirect.phpt | 2 +- Zend/tests/enum/no-implement-serializable.phpt | 2 +- Zend/tests/enum/no-name-property.phpt | 2 +- Zend/tests/enum/no-properties.phpt | 2 +- Zend/tests/enum/no-static-properties.phpt | 2 +- Zend/tests/enum/no-value-property.phpt | 2 +- Zend/tests/enum/traits-no-__construct.phpt | 2 +- Zend/tests/enum/traits-no-forbidden-methods.phpt | 2 +- Zend/tests/enum/traits-no-properties.phpt | 2 +- Zend/zend_compile.c | 2 +- Zend/zend_enum.c | 12 ++++++------ 29 files changed, 184 insertions(+), 25 deletions(-) create mode 100644 Zend/tests/enum/__clone.phpt create mode 100644 Zend/tests/enum/__debugInfo.phpt create mode 100644 Zend/tests/enum/__serialize.phpt create mode 100644 Zend/tests/enum/__set.phpt create mode 100644 Zend/tests/enum/__set_state.phpt create mode 100644 Zend/tests/enum/__sleep.phpt create mode 100644 Zend/tests/enum/__toString.phpt create mode 100644 Zend/tests/enum/__unserialize.phpt create mode 100644 Zend/tests/enum/__unset.phpt create mode 100644 Zend/tests/enum/__wakeup.phpt diff --git a/Zend/tests/enum/__clone.phpt b/Zend/tests/enum/__clone.phpt new file mode 100644 index 00000000000..fd4b4c43173 --- /dev/null +++ b/Zend/tests/enum/__clone.phpt @@ -0,0 +1,15 @@ +--TEST-- +Enum __clone +--FILE-- + +--EXPECTF-- +Fatal error: Enum Foo cannot include magic method __clone in %s on line %d diff --git a/Zend/tests/enum/__debugInfo.phpt b/Zend/tests/enum/__debugInfo.phpt new file mode 100644 index 00000000000..33e0f49851f --- /dev/null +++ b/Zend/tests/enum/__debugInfo.phpt @@ -0,0 +1,16 @@ +--TEST-- +Enum __debugInfo +--FILE-- +cases(); + } +} + +?> +--EXPECTF-- +Fatal error: Enum Foo cannot include magic method __debugInfo in %s on line %d diff --git a/Zend/tests/enum/__get.phpt b/Zend/tests/enum/__get.phpt index 885cc2f2c83..6c77d119b7c 100644 --- a/Zend/tests/enum/__get.phpt +++ b/Zend/tests/enum/__get.phpt @@ -14,4 +14,4 @@ enum Foo { ?> --EXPECTF-- -Fatal error: Enum may not include __get in %s on line %d +Fatal error: Enum Foo cannot include magic method __get in %s on line %d diff --git a/Zend/tests/enum/__isset.phpt b/Zend/tests/enum/__isset.phpt index 76409f075b2..087d7d0b172 100644 --- a/Zend/tests/enum/__isset.phpt +++ b/Zend/tests/enum/__isset.phpt @@ -13,4 +13,4 @@ enum Foo { ?> --EXPECTF-- -Fatal error: Enum may not include __isset in %s on line %d +Fatal error: Enum Foo cannot include magic method __isset in %s on line %d diff --git a/Zend/tests/enum/__serialize.phpt b/Zend/tests/enum/__serialize.phpt new file mode 100644 index 00000000000..635bd439642 --- /dev/null +++ b/Zend/tests/enum/__serialize.phpt @@ -0,0 +1,16 @@ +--TEST-- +Enum __serialize +--FILE-- +cases(); + } +} + +?> +--EXPECTF-- +Fatal error: Enum Foo cannot include magic method __serialize in %s on line %d diff --git a/Zend/tests/enum/__set.phpt b/Zend/tests/enum/__set.phpt new file mode 100644 index 00000000000..7fa0fcfb3a4 --- /dev/null +++ b/Zend/tests/enum/__set.phpt @@ -0,0 +1,16 @@ +--TEST-- +Enum __set +--FILE-- + +--EXPECTF-- +Fatal error: Enum Foo cannot include magic method __set in %s on line %d diff --git a/Zend/tests/enum/__set_state.phpt b/Zend/tests/enum/__set_state.phpt new file mode 100644 index 00000000000..b2bf0717430 --- /dev/null +++ b/Zend/tests/enum/__set_state.phpt @@ -0,0 +1,16 @@ +--TEST-- +Enum __set_state +--FILE-- + +--EXPECTF-- +Fatal error: Enum Foo cannot include magic method __set_state in %s on line %d diff --git a/Zend/tests/enum/__sleep.phpt b/Zend/tests/enum/__sleep.phpt new file mode 100644 index 00000000000..4da08e6a4d3 --- /dev/null +++ b/Zend/tests/enum/__sleep.phpt @@ -0,0 +1,16 @@ +--TEST-- +Enum __sleep +--FILE-- + +--EXPECTF-- +Fatal error: Enum Foo cannot include magic method __sleep in %s on line %d diff --git a/Zend/tests/enum/__toString.phpt b/Zend/tests/enum/__toString.phpt new file mode 100644 index 00000000000..9407e482fb7 --- /dev/null +++ b/Zend/tests/enum/__toString.phpt @@ -0,0 +1,16 @@ +--TEST-- +Enum __toString +--FILE-- +name; + } +} + +?> +--EXPECTF-- +Fatal error: Enum Foo cannot include magic method __toString in %s on line %d diff --git a/Zend/tests/enum/__unserialize.phpt b/Zend/tests/enum/__unserialize.phpt new file mode 100644 index 00000000000..f9d59417685 --- /dev/null +++ b/Zend/tests/enum/__unserialize.phpt @@ -0,0 +1,16 @@ +--TEST-- +Enum __unserialize +--FILE-- + +--EXPECTF-- +Fatal error: Enum Foo cannot include magic method __unserialize in %s on line %d diff --git a/Zend/tests/enum/__unset.phpt b/Zend/tests/enum/__unset.phpt new file mode 100644 index 00000000000..e2ada98688e --- /dev/null +++ b/Zend/tests/enum/__unset.phpt @@ -0,0 +1,16 @@ +--TEST-- +Enum __unset +--FILE-- + +--EXPECTF-- +Fatal error: Enum Foo cannot include magic method __unset in %s on line %d diff --git a/Zend/tests/enum/__wakeup.phpt b/Zend/tests/enum/__wakeup.phpt new file mode 100644 index 00000000000..8aea17ae53f --- /dev/null +++ b/Zend/tests/enum/__wakeup.phpt @@ -0,0 +1,16 @@ +--TEST-- +Enum __wakeup +--FILE-- + +--EXPECTF-- +Fatal error: Enum Foo cannot include magic method __wakeup in %s on line %d diff --git a/Zend/tests/enum/backed-from-invalid-int.phpt b/Zend/tests/enum/backed-from-invalid-int.phpt index d976f3d0fbd..d40cae30e6c 100644 --- a/Zend/tests/enum/backed-from-invalid-int.phpt +++ b/Zend/tests/enum/backed-from-invalid-int.phpt @@ -16,4 +16,4 @@ try { ?> --EXPECT-- -2 is not a valid backing value for enum "Foo" +2 is not a valid backing value for enum Foo diff --git a/Zend/tests/enum/backed-from-invalid-string.phpt b/Zend/tests/enum/backed-from-invalid-string.phpt index db8b791d8be..c6d784872ef 100644 --- a/Zend/tests/enum/backed-from-invalid-string.phpt +++ b/Zend/tests/enum/backed-from-invalid-string.phpt @@ -18,4 +18,4 @@ try { ?> --EXPECT-- -"A" is not a valid backing value for enum "Suit" +"A" is not a valid backing value for enum Suit diff --git a/Zend/tests/enum/backed-from-invalid-type.phpt b/Zend/tests/enum/backed-from-invalid-type.phpt index 3f35bef64f5..b4e0e6d6164 100644 --- a/Zend/tests/enum/backed-from-invalid-type.phpt +++ b/Zend/tests/enum/backed-from-invalid-type.phpt @@ -30,5 +30,5 @@ try { ?> --EXPECT-- -"42" is not a valid backing value for enum "Suit" +"42" is not a valid backing value for enum Suit Foo::from(): Argument #1 ($value) must be of type int, string given diff --git a/Zend/tests/enum/internal_enums.phpt b/Zend/tests/enum/internal_enums.phpt index 5e36baae302..ae26e24cd7e 100644 --- a/Zend/tests/enum/internal_enums.phpt +++ b/Zend/tests/enum/internal_enums.phpt @@ -86,9 +86,9 @@ enum(ZendTestIntEnum::Foo) enum(ZendTestIntEnum::Foo) enum(ZendTestIntEnum::Foo) enum(ZendTestIntEnum::Foo) -ValueError: 2 is not a valid backing value for enum "ZendTestIntEnum" +ValueError: 2 is not a valid backing value for enum ZendTestIntEnum NULL -ValueError: 2 is not a valid backing value for enum "ZendTestIntEnum" +ValueError: 2 is not a valid backing value for enum ZendTestIntEnum NULL enum(ZendTestIntEnum::Baz) enum(ZendTestIntEnum::Baz) diff --git a/Zend/tests/enum/no-constructors.phpt b/Zend/tests/enum/no-constructors.phpt index 70504e14eb3..862c9ebb7b2 100644 --- a/Zend/tests/enum/no-constructors.phpt +++ b/Zend/tests/enum/no-constructors.phpt @@ -9,4 +9,4 @@ enum Foo { ?> --EXPECTF-- -Fatal error: Enum may not include __construct in %s on line %d +Fatal error: Enum Foo cannot include magic method __construct in %s on line %d diff --git a/Zend/tests/enum/no-destruct.phpt b/Zend/tests/enum/no-destruct.phpt index 730c29f8476..107478b9762 100644 --- a/Zend/tests/enum/no-destruct.phpt +++ b/Zend/tests/enum/no-destruct.phpt @@ -9,4 +9,4 @@ enum Foo { ?> --EXPECTF-- -Fatal error: Enum may not include __destruct in %s on line %d +Fatal error: Enum Foo cannot include magic method __destruct in %s on line %d diff --git a/Zend/tests/enum/no-implement-serializable-indirect.phpt b/Zend/tests/enum/no-implement-serializable-indirect.phpt index efd9229d9ed..43231b60da8 100644 --- a/Zend/tests/enum/no-implement-serializable-indirect.phpt +++ b/Zend/tests/enum/no-implement-serializable-indirect.phpt @@ -23,4 +23,4 @@ var_dump(unserialize(serialize(Foo::Bar))); --EXPECTF-- 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 -Fatal error: Enums may not implement the Serializable interface in %s on line %d +Fatal error: Enum Foo cannot implement the Serializable interface in %s on line %d diff --git a/Zend/tests/enum/no-implement-serializable.phpt b/Zend/tests/enum/no-implement-serializable.phpt index 355d62b71ba..1099cc725c8 100644 --- a/Zend/tests/enum/no-implement-serializable.phpt +++ b/Zend/tests/enum/no-implement-serializable.phpt @@ -21,4 +21,4 @@ var_dump(unserialize(serialize(Foo::Bar))); --EXPECTF-- 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 -Fatal error: Enums may not implement the Serializable interface in %s on line %d +Fatal error: Enum Foo cannot implement the Serializable interface in %s on line %d diff --git a/Zend/tests/enum/no-name-property.phpt b/Zend/tests/enum/no-name-property.phpt index a565c08e830..6ea1e1a0b00 100644 --- a/Zend/tests/enum/no-name-property.phpt +++ b/Zend/tests/enum/no-name-property.phpt @@ -9,4 +9,4 @@ enum Foo { ?> --EXPECTF-- -Fatal error: Enums may not include properties in %s on line %d +Fatal error: Enum Foo cannot include properties in %s on line %d diff --git a/Zend/tests/enum/no-properties.phpt b/Zend/tests/enum/no-properties.phpt index e846845d222..fb396b403e3 100644 --- a/Zend/tests/enum/no-properties.phpt +++ b/Zend/tests/enum/no-properties.phpt @@ -9,4 +9,4 @@ enum Foo { ?> --EXPECTF-- -Fatal error: Enums may not include properties in %s on line %d +Fatal error: Enum Foo cannot include properties in %s on line %d diff --git a/Zend/tests/enum/no-static-properties.phpt b/Zend/tests/enum/no-static-properties.phpt index 4b823e98e9f..87358263778 100644 --- a/Zend/tests/enum/no-static-properties.phpt +++ b/Zend/tests/enum/no-static-properties.phpt @@ -9,4 +9,4 @@ enum Foo { ?> --EXPECTF-- -Fatal error: Enums may not include properties in %s on line %d +Fatal error: Enum Foo cannot include properties in %s on line %d diff --git a/Zend/tests/enum/no-value-property.phpt b/Zend/tests/enum/no-value-property.phpt index d8b12f2ca8a..efa8a7d3420 100644 --- a/Zend/tests/enum/no-value-property.phpt +++ b/Zend/tests/enum/no-value-property.phpt @@ -9,4 +9,4 @@ enum Foo: int { ?> --EXPECTF-- -Fatal error: Enums may not include properties in %s on line %d +Fatal error: Enum Foo cannot include properties in %s on line %d diff --git a/Zend/tests/enum/traits-no-__construct.phpt b/Zend/tests/enum/traits-no-__construct.phpt index 0529a2a9890..4bac34295b8 100644 --- a/Zend/tests/enum/traits-no-__construct.phpt +++ b/Zend/tests/enum/traits-no-__construct.phpt @@ -18,4 +18,4 @@ var_dump(Bar::Baz); ?> --EXPECTF-- -Fatal error: Enum may not include __construct in %s on line %d +Fatal error: Enum Bar cannot include magic method __construct in %s on line %d diff --git a/Zend/tests/enum/traits-no-forbidden-methods.phpt b/Zend/tests/enum/traits-no-forbidden-methods.phpt index 1f310f48cd0..36e4ce780e3 100644 --- a/Zend/tests/enum/traits-no-forbidden-methods.phpt +++ b/Zend/tests/enum/traits-no-forbidden-methods.phpt @@ -18,4 +18,4 @@ enum Suit { ?> --EXPECTF-- -Fatal error: Enum may not include __construct in %s on line %d +Fatal error: Enum Suit cannot include magic method __construct in %s on line %d diff --git a/Zend/tests/enum/traits-no-properties.phpt b/Zend/tests/enum/traits-no-properties.phpt index 5a6faf9deac..0cc3c9cf387 100644 --- a/Zend/tests/enum/traits-no-properties.phpt +++ b/Zend/tests/enum/traits-no-properties.phpt @@ -22,4 +22,4 @@ enum Suit { ?> --EXPECTF-- -Fatal error: Enum "Suit" may not include properties in %s on line %d +Fatal error: Enum Suit cannot include properties in %s on line %d diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index e3e986e193c..487c15b589e 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -7407,7 +7407,7 @@ static void zend_compile_prop_decl(zend_ast *ast, zend_ast *type_ast, uint32_t f } if (ce->ce_flags & ZEND_ACC_ENUM) { - zend_error_noreturn(E_COMPILE_ERROR, "Enums may not include properties"); + zend_error_noreturn(E_COMPILE_ERROR, "Enum %s cannot include properties", ZSTR_VAL(ce->name)); } if (flags & ZEND_ACC_ABSTRACT) { diff --git a/Zend/zend_enum.c b/Zend/zend_enum.c index 16c3753e7c9..59befde7321 100644 --- a/Zend/zend_enum.c +++ b/Zend/zend_enum.c @@ -28,7 +28,7 @@ #define ZEND_ENUM_DISALLOW_MAGIC_METHOD(propertyName, methodName) \ do { \ if (ce->propertyName) { \ - zend_error_noreturn(E_COMPILE_ERROR, "Enum may not include %s", methodName); \ + zend_error_noreturn(E_COMPILE_ERROR, "Enum %s cannot include magic method %s", ZSTR_VAL(ce->name), methodName); \ } \ } while (0); @@ -67,7 +67,7 @@ static void zend_verify_enum_properties(zend_class_entry *ce) continue; } // FIXME: File/line number for traits? - zend_error_noreturn(E_COMPILE_ERROR, "Enum \"%s\" may not include properties", + zend_error_noreturn(E_COMPILE_ERROR, "Enum %s cannot include properties", ZSTR_VAL(ce->name)); } ZEND_HASH_FOREACH_END(); } @@ -99,7 +99,7 @@ static void zend_verify_enum_magic_methods(zend_class_entry *ce) const char *forbidden_method = forbidden_methods[i]; if (zend_hash_str_exists(&ce->function_table, forbidden_method, strlen(forbidden_method))) { - zend_error_noreturn(E_COMPILE_ERROR, "Enum may not include magic method %s", forbidden_method); + zend_error_noreturn(E_COMPILE_ERROR, "Enum %s cannot include magic method %s", ZSTR_VAL(ce->name), forbidden_method); } } } @@ -108,7 +108,7 @@ static void zend_verify_enum_interfaces(zend_class_entry *ce) { if (zend_class_implements_interface(ce, zend_ce_serializable)) { zend_error_noreturn(E_COMPILE_ERROR, - "Enums may not implement the Serializable interface"); + "Enum %s cannot implement the Serializable interface", ZSTR_VAL(ce->name)); } } @@ -307,10 +307,10 @@ not_found: } if (ce->enum_backing_type == IS_LONG) { - zend_value_error(ZEND_LONG_FMT " is not a valid backing value for enum \"%s\"", long_key, ZSTR_VAL(ce->name)); + zend_value_error(ZEND_LONG_FMT " is not a valid backing value for enum %s", long_key, ZSTR_VAL(ce->name)); } else { ZEND_ASSERT(ce->enum_backing_type == IS_STRING); - zend_value_error("\"%s\" is not a valid backing value for enum \"%s\"", ZSTR_VAL(string_key), ZSTR_VAL(ce->name)); + zend_value_error("\"%s\" is not a valid backing value for enum %s", ZSTR_VAL(string_key), ZSTR_VAL(ce->name)); } return FAILURE; }