Skip to content

Stdlib: json_encode(unit enum) JSON_ERROR_NON_BACKED_ENUM (#22681, #22688)#22726

Merged
PurHur merged 1 commit into
masterfrom
agent/stdlib-22681-json-unit-enum-msg
Jul 23, 2026
Merged

Stdlib: json_encode(unit enum) JSON_ERROR_NON_BACKED_ENUM (#22681, #22688)#22726
PurHur merged 1 commit into
masterfrom
agent/stdlib-22681-json-unit-enum-msg

Conversation

@PurHur

@PurHur PurHur commented Jul 23, 2026

Copy link
Copy Markdown
Owner

Summary

  • VmJson::exportEnumCase now rejects unit enums with JSON_ERROR_NON_BACKED_ENUM (11) and Zend's Non-backed enums have no default serialization message (php-src ext/json/json_encoder.c).
  • Removed the mistaken forward-profile ValueError path (CompilerVersion::jsonEncodeUnitEnumValueError() always false) so PHP_COMPILER_PROFILE=8.4 matches Zend 8.2–8.4 (false + last-error; JsonException only with JSON_THROW_ON_ERROR).
  • Compliance + repro guards for default and forward profiles.

Closes #22681
Closes #22688

php-src reference

  • ext/json/json_encoder.c — unit enum → JSON_ERROR_NON_BACKED_ENUM
  • PHP implementation: ext/standard/VmJson.php (shared by VM + JsonEncodeJitHelper JIT/AOT)

Verification

# Zend vs VM vs JIT (identical)
php test/repro/maintainer_gap_json_encode_unit_enum_non_backed.php
php bin/vm.php test/repro/maintainer_gap_json_encode_unit_enum_non_backed.php
php bin/jit.php test/repro/maintainer_gap_json_encode_unit_enum_non_backed.php
PHP_COMPILER_PROFILE=8.4 php bin/vm.php test/repro/maintainer_gap_json_encode_unit_enum_non_backed.php
# → false / 11:Non-backed enums… / JsonException:Non-backed enums…

php -d memory_limit=512M vendor/bin/phpunit --filter 'json_encode_unit_enum' test/compliance/VMTest.php
# OK (2 tests)

php -d memory_limit=512M vendor/bin/phpunit --filter JsonEncodeUnitEnum test/unit/CompilerVersionGateTest.php
# OK (1 test)

AOT note: bin/compile.php of a unit-enum encode smoke links via JsonEncodeJitHelper (same SSOT) but native run currently segfaults on enum materialization (phpc: fatal signal after c:main_before_php) — pre-existing, also seen for backed-enum encode; not introduced by this message/error-code fix. JIT path (same helper) is green.

Gate snapshot (pre-change master, this host)

Gate Status
inventory OK 6479/6479
spine OK
vm-driver-probe OK
release-readiness user_release_ready: nonorth-star5-fast step 4f-m gen-0 fingerprint (#8713 / PR #22717)

Made with Cursor

#22688)

Match php-src ext/json: return false with error 11 / Zend message, and never ValueError on forward 8.4 profiles. JSON_THROW_ON_ERROR raises JsonException with the same text.

Co-authored-by: Cursor <cursoragent@cursor.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant