diff --git a/Zend/tests/enum/json_encode.phpt b/Zend/tests/enum/json_encode.phpt index 12ed0d3d445..f1174db7ae8 100644 --- a/Zend/tests/enum/json_encode.phpt +++ b/Zend/tests/enum/json_encode.phpt @@ -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 diff --git a/ext/json/json.c b/ext/json/json.c index b21ed4d14b2..c66a48c49ea 100644 --- a/ext/json/json.c +++ b/ext/json/json.c @@ -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; }