mirror of
https://github.com/php/php-src.git
synced 2026-03-24 08:12:21 +01:00
Enum error message consistency (#9350)
This commit is contained in:
15
Zend/tests/enum/__clone.phpt
Normal file
15
Zend/tests/enum/__clone.phpt
Normal file
@@ -0,0 +1,15 @@
|
||||
--TEST--
|
||||
Enum __clone
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
enum Foo {
|
||||
case Bar;
|
||||
|
||||
public function __clone() {
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
--EXPECTF--
|
||||
Fatal error: Enum Foo cannot include magic method __clone in %s on line %d
|
||||
16
Zend/tests/enum/__debugInfo.phpt
Normal file
16
Zend/tests/enum/__debugInfo.phpt
Normal file
@@ -0,0 +1,16 @@
|
||||
--TEST--
|
||||
Enum __debugInfo
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
enum Foo {
|
||||
case Bar;
|
||||
|
||||
public function __debugInfo(): array {
|
||||
return $this->cases();
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
--EXPECTF--
|
||||
Fatal error: Enum Foo cannot include magic method __debugInfo in %s on line %d
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
16
Zend/tests/enum/__serialize.phpt
Normal file
16
Zend/tests/enum/__serialize.phpt
Normal file
@@ -0,0 +1,16 @@
|
||||
--TEST--
|
||||
Enum __serialize
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
enum Foo {
|
||||
case Bar;
|
||||
|
||||
public function __serialize(): array {
|
||||
return $this->cases();
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
--EXPECTF--
|
||||
Fatal error: Enum Foo cannot include magic method __serialize in %s on line %d
|
||||
16
Zend/tests/enum/__set.phpt
Normal file
16
Zend/tests/enum/__set.phpt
Normal file
@@ -0,0 +1,16 @@
|
||||
--TEST--
|
||||
Enum __set
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
enum Foo {
|
||||
case Bar;
|
||||
|
||||
public function __set(string $name, mixed $value)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
--EXPECTF--
|
||||
Fatal error: Enum Foo cannot include magic method __set in %s on line %d
|
||||
16
Zend/tests/enum/__set_state.phpt
Normal file
16
Zend/tests/enum/__set_state.phpt
Normal file
@@ -0,0 +1,16 @@
|
||||
--TEST--
|
||||
Enum __set_state
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
enum Foo {
|
||||
case Bar;
|
||||
|
||||
public static function __set_state(array $properties): object {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
--EXPECTF--
|
||||
Fatal error: Enum Foo cannot include magic method __set_state in %s on line %d
|
||||
16
Zend/tests/enum/__sleep.phpt
Normal file
16
Zend/tests/enum/__sleep.phpt
Normal file
@@ -0,0 +1,16 @@
|
||||
--TEST--
|
||||
Enum __sleep
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
enum Foo {
|
||||
case Bar;
|
||||
|
||||
public function __sleep(): array {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
--EXPECTF--
|
||||
Fatal error: Enum Foo cannot include magic method __sleep in %s on line %d
|
||||
16
Zend/tests/enum/__toString.phpt
Normal file
16
Zend/tests/enum/__toString.phpt
Normal file
@@ -0,0 +1,16 @@
|
||||
--TEST--
|
||||
Enum __toString
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
enum Foo {
|
||||
case Bar;
|
||||
|
||||
public function __toString(): string {
|
||||
return $this->name;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
--EXPECTF--
|
||||
Fatal error: Enum Foo cannot include magic method __toString in %s on line %d
|
||||
16
Zend/tests/enum/__unserialize.phpt
Normal file
16
Zend/tests/enum/__unserialize.phpt
Normal file
@@ -0,0 +1,16 @@
|
||||
--TEST--
|
||||
Enum __unserialize
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
enum Foo {
|
||||
case Bar;
|
||||
|
||||
public function __unserialize(array $data) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
--EXPECTF--
|
||||
Fatal error: Enum Foo cannot include magic method __unserialize in %s on line %d
|
||||
16
Zend/tests/enum/__unset.phpt
Normal file
16
Zend/tests/enum/__unset.phpt
Normal file
@@ -0,0 +1,16 @@
|
||||
--TEST--
|
||||
Enum __unset
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
enum Foo {
|
||||
case Bar;
|
||||
|
||||
public function __unset($property) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
--EXPECTF--
|
||||
Fatal error: Enum Foo cannot include magic method __unset in %s on line %d
|
||||
16
Zend/tests/enum/__wakeup.phpt
Normal file
16
Zend/tests/enum/__wakeup.phpt
Normal file
@@ -0,0 +1,16 @@
|
||||
--TEST--
|
||||
Enum __wakeup
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
enum Foo {
|
||||
case Bar;
|
||||
|
||||
public function __wakeup() {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
--EXPECTF--
|
||||
Fatal error: Enum Foo cannot include magic method __wakeup in %s on line %d
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user