Merge branch 'PHP-8.1'

* PHP-8.1:
  Register JSON_ERROR_NON_BACKED_ENUM constant (#8285)
This commit is contained in:
Ilija Tovilo 2022-03-31 14:31:43 +02:00
commit 54440fa6eb
No known key found for this signature in database
GPG key ID: A4F5D403F118200A
2 changed files with 7 additions and 0 deletions

View file

@ -26,6 +26,10 @@ enum CustomFoo implements JsonSerializable {
function test($value) {
var_dump(json_encode($value));
echo json_last_error_msg() . "\n";
if (json_last_error() !== JSON_ERROR_NONE) {
echo json_last_error() . ' === ' . JSON_ERROR_NON_BACKED_ENUM . ":\n";
var_dump(json_last_error() === JSON_ERROR_NON_BACKED_ENUM);
}
try {
var_dump(json_encode($value, JSON_THROW_ON_ERROR));
@ -44,6 +48,8 @@ test(CustomFoo::Bar);
--EXPECT--
bool(false)
Non-backed enums have no default serialization
11 === 11:
bool(true)
JsonException: Non-backed enums have no default serialization
string(1) "0"
No error

View file

@ -83,6 +83,7 @@ static PHP_MINIT_FUNCTION(json)
PHP_JSON_REGISTER_CONSTANT("JSON_ERROR_UNSUPPORTED_TYPE", PHP_JSON_ERROR_UNSUPPORTED_TYPE);
PHP_JSON_REGISTER_CONSTANT("JSON_ERROR_INVALID_PROPERTY_NAME", PHP_JSON_ERROR_INVALID_PROPERTY_NAME);
PHP_JSON_REGISTER_CONSTANT("JSON_ERROR_UTF16", PHP_JSON_ERROR_UTF16);
PHP_JSON_REGISTER_CONSTANT("JSON_ERROR_NON_BACKED_ENUM", PHP_JSON_ERROR_NON_BACKED_ENUM);
return SUCCESS;
}