Skip to content

Stdlib: json_encode() — enum case operands must match Zend JSON output (ext/json/php_json.c) #6130

Description

@PurHur

Summary

json_encode() on enum case operands must match Zend/php-src JSON serialization rules. Today the VM path fails in VmJson::export() with a generic LogicException before JSON is produced.

Strictness: php-src-strict — match ext/json/php_json.c enum handling.

php-src reference

  • ext/json/php_json.cphp_json_encode() / enum case handling
  • Zend/zend_enum.c — backed vs unit enum JSON representation

Repro

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && php bin/vm.php test/repro-maintainer/parity_json_encode_enum.php'

Compare with Zend in the same container:

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && php test/repro-maintainer/parity_json_encode_enum.php'

Zend PHP 8.2 (expected):

unit: 
backed_string: "x"
backed_int: 1

php-compiler VM (actual):

unit: json_encode() value type not supported in this compiler build

Expected behavior

Operand Zend JSON
unit enum case "" (empty JSON string)
backed string case quoted backing value, e.g. "x"
backed int case numeric backing value, e.g. 1

Implementation hints (PHP-in-PHP)

  • Extend ext/standard/VmJson.php::export() for Variable::TYPE_ENUM_CASE.
  • Wire the same rules in ext/standard/json_encode.php JIT lowering.
  • Add compliance .phpt under test/compliance/cases/stdlib/ + JIT/AOT fixtures.
  • Do not add C runtime logic in runtime/.

Verification

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && vendor/bin/phpunit --filter json_encode_enum test/compliance/'

Maintainer repro: test/repro-maintainer/parity_json_encode_enum.php

Category

php-in-php | stdlib

Done when

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 apps

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions