Skip to content

Regression: json_encode(unit enum) json_last_error_msg wrong — Zend Non-backed enums… (ext/json/php_json.c) #22681

Description

@PurHur

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

  • Unit-enum json_encode last-error / throw message matches Zend on VM/JIT/AOT
  • Compliance .phpt under test/compliance/cases/json/
  • php-src-strict; no php-compiler-strict shortcut

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:vmVirtual machinebugSomething isn't workingimplementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claimphase-4:stdlibPhase 4 – stdlib for web appsstdlib

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions