Skip to content

Stdlib: json_encode() on unit enum cases — ValueError parity (ext/json/php_json.c) #5683

Description

@PurHur

Category

stdlib

Problem

#4446 tracks backed enum json_encode → backing scalar. Unit enums (no backing type) are a separate Zend path: json_encode(E::A) must throw ValueError: json_encode(): Argument #1 (\$value) contains an invalid JSON type (PHP 8.3+).

This compiler returns a build-specific LogicException (json_encode() value type not supported in this compiler build) — wrong class/message and blocks parity tests.

php-src reference

Repro

<?php
enum E { case A; }
try {
    json_encode(E::A);
} catch (Throwable $e) {
    echo get_class($e), ': ', $e->getMessage(), "\n";
}
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && php bin/vm.php repro.php'
php repro.php
Engine Output
Zend ValueError: json_encode(): Argument #1 ($value) contains an invalid JSON type
This compiler VM LogicException: json_encode() value type not supported…

Scope (this repo)

Layer Path
VM ext/standard/VmJson.php (or json module), enum case type dispatch
Bootstrap pairs #4795 native VmJson (no host json_encode)
Tests test/compliance/cases/stdlib/json_encode_unit_enum.phpt

Done when

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