Skip to content

Commit 54440fa

Browse files
committed
Merge branch 'PHP-8.1'
* PHP-8.1: Register JSON_ERROR_NON_BACKED_ENUM constant (#8285)
2 parents 15129ab + 2145f80 commit 54440fa

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

Zend/tests/enum/json_encode.phpt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ enum CustomFoo implements JsonSerializable {
2626
function test($value) {
2727
var_dump(json_encode($value));
2828
echo json_last_error_msg() . "\n";
29+
if (json_last_error() !== JSON_ERROR_NONE) {
30+
echo json_last_error() . ' === ' . JSON_ERROR_NON_BACKED_ENUM . ":\n";
31+
var_dump(json_last_error() === JSON_ERROR_NON_BACKED_ENUM);
32+
}
2933

3034
try {
3135
var_dump(json_encode($value, JSON_THROW_ON_ERROR));
@@ -44,6 +48,8 @@ test(CustomFoo::Bar);
4448
--EXPECT--
4549
bool(false)
4650
Non-backed enums have no default serialization
51+
11 === 11:
52+
bool(true)
4753
JsonException: Non-backed enums have no default serialization
4854
string(1) "0"
4955
No error

ext/json/json.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ static PHP_MINIT_FUNCTION(json)
8383
PHP_JSON_REGISTER_CONSTANT("JSON_ERROR_UNSUPPORTED_TYPE", PHP_JSON_ERROR_UNSUPPORTED_TYPE);
8484
PHP_JSON_REGISTER_CONSTANT("JSON_ERROR_INVALID_PROPERTY_NAME", PHP_JSON_ERROR_INVALID_PROPERTY_NAME);
8585
PHP_JSON_REGISTER_CONSTANT("JSON_ERROR_UTF16", PHP_JSON_ERROR_UTF16);
86+
PHP_JSON_REGISTER_CONSTANT("JSON_ERROR_NON_BACKED_ENUM", PHP_JSON_ERROR_NON_BACKED_ENUM);
8687

8788
return SUCCESS;
8889
}

0 commit comments

Comments
 (0)