Category
stdlib · php-src-strict · JSON enum encoding (pillar 4)
Problem
json_encode on a unit (non-backed) enum case returns false on both engines, but json_last_error_msg() diverges:
- Zend:
Non-backed enums have no default serialization
- VM:
Type is not supported
Backed enums already encode to their scalar (OK). Respin surface of closed #6130 / #5683 — encoding result is false, but the error string must match php-src for debuggers and JSON_THROW_ON_ERROR message text.
Probed 2026-07-23 on master VM vs host Zend 8.2.32.
| Repro |
Zend 8.2+ |
VM (2026-07-23) |
json_encode(U::X) (unit enum) |
false |
false |
json_last_error_msg() after |
Non-backed enums have no default serialization |
Type is not supported |
php-src reference
PHP implementation target
ext/json/ or JSON encode helper — special-case unit enum before generic unsupported-type path; set last-error string to Zend wording
JSON_THROW_ON_ERROR must surface the same message
- PHP-in-PHP only
Repro
./script/docker-exec.sh -- bash -lc 'php bin/vm.php -r '\"'\"'
enum U { case X; }
var_export(json_encode(U::X)); echo \"\n\";
echo json_last_error_msg(), \"\n\";
'\"'\"''
Expected (Zend): false then Non-backed enums have no default serialization
Actual (VM): false then Type is not supported
Done when
Category
stdlib· php-src-strict · JSON enum encoding (pillar 4)Problem
json_encodeon a unit (non-backed) enum case returnsfalseon both engines, butjson_last_error_msg()diverges:Non-backed enums have no default serializationType is not supportedBacked enums already encode to their scalar (OK). Respin surface of closed #6130 / #5683 — encoding result is false, but the error string must match php-src for debuggers and
JSON_THROW_ON_ERRORmessage text.Probed 2026-07-23 on master VM vs host Zend 8.2.32.
json_encode(U::X)(unit enum)falsefalsejson_last_error_msg()afterNon-backed enums have no default serializationType is not supportedphp-src reference
ext/json/json_encoder.c— unit enum reject path / error messageZend/zend_enum.c— backed vs unit distinctionPHP implementation target
ext/json/or JSON encode helper — special-case unit enum before generic unsupported-type path; set last-error string to Zend wordingJSON_THROW_ON_ERRORmust surface the same messageRepro
Expected (Zend):
falsethenNon-backed enums have no default serializationActual (VM):
falsethenType is not supportedDone when
json_encodelast-error / throw message matches Zend on VM/JIT/AOT.phptundertest/compliance/cases/json/