Skip to content

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

Description

@PurHur

Category

stdlib

Problem

json_validate() (PHP 8.3+) must reject non-string $json operands with catchable TypeError like Zend. VM accepts backed enum cases and coerces via backing scalar — repro prints uncaught instead of TypeError.

Independent of enum object materialization (#8746): even if enum cases were objects, json_validate(E::A) must still TypeError (php-src Z_PARAM_STR).

php-src reference

Repro

test/repro/maintainer_gap_json_validate_enum.php:

<?php
enum E: string { case A = 'x'; }
try {
    json_validate(E::A);
    echo "uncaught\n";
} catch (TypeError $e) {
    echo 'TypeError: ', $e->getMessage(), "\n";
}
php bin/vm.php test/repro/maintainer_gap_json_validate_enum.php

Zend PHP 8.3+: TypeError: json_validate(): Argument #1 ($json) must be of type string, E given
VM today: uncaught

Scope

  • ext/standard/json_validate.php — VM path uses VmString::coerceStringBuiltinArg() (guard must run under php-src-strict)
  • ext/standard/JitJsonValidate.php — JitStringBuiltinArg::lower() mirror
  • Shared guards: VmString::coerceStringBuiltinArg, RuntimeStrictness::enforceStringBuiltinParityGuards()

Done when (php-src-strict)

Links

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