Register JSON_ERROR_NON_BACKED_ENUM constant (#8285)

Fixes GH-8238
This commit is contained in:
Ilija Tovilo 2022-03-31 14:31:17 +02:00 committed by GitHub
parent ced5581eca
commit 2145f80d4b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 0 deletions

1
NEWS
View File

@ -347,6 +347,7 @@ PHP NEWS
- JSON:
. Fixed bug #81532 (Change of $depth behaviour in json_encode() on PHP 8.1).
(Nikita)
. Fixed bug GH-8238 (Register JSON_ERROR_NON_BACKED_ENUM constant). (ilutov)
- LDAP:
. Convert resource<ldap link> to object \LDAP\Connection. (Máté)

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;
}