Skip to content

Stdlib: json_decode() — enum case json operand must TypeError (ext/json/php_json.c, php-src-strict) #8844

Description

@PurHur

Summary

json_decode() must reject backed enum case operands with TypeError under php-src-strict. VM currently coerces enum cases to backing scalars and decodes JSON from the backing string.

php-src reference: ext/json/php_json.c — php_json_decode() validates $json as string before parsing; enum cases are objects, not strings.

PHP implementation target: ext/json/ VM builtin + VmString::coerceStringBuiltinArg / JitStringBuiltinArg guard on the json operand (no new C runtime).

Repro

test/repro/maintainer_json_decode_enum.php:

php bin/vm.php test/repro/maintainer_json_decode_enum.php
# VM today: int(1) from backing string '{"x":1}'
php test/repro/maintainer_json_decode_enum.php
# Zend: TypeError

Observed (2026-06-15):

  • Zend: TypeError: json_decode(): Argument #1 ($json) must be of type string, E given
  • VM: int(1) — decodes backing scalar

Done when (php-src-strict)

Related

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 machineenhancementNew feature or requestimplementation-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