Skip to content

Stdlib: json_validate()/preg_split()/preg_grep()/preg_quote() — enum operands must TypeError not LogicException (php-src-strict) #5999

Description

@PurHur

Summary

Several stdlib builtins reject enum case operands with LogicException and compiler-specific messages. Zend/php-src rejects them with TypeError via Z_PARAM_STR / internal string checks (php-src-strict).

Affected today on VM:

Function Repro Current Zend
json_validate() test/repro/maintainer_gap_json_validate_enum.php LogicException: argument #1 must be a string in this compiler build TypeError
preg_split() test/repro/maintainer_gap_preg_split_enum.php LogicException: pattern must be a string… TypeError
preg_grep() test/repro/maintainer_gap_preg_grep_enum.php LogicException: pattern must be a string… TypeError
preg_quote() test/repro/maintainer_gap_preg_quote_enum.php LogicException: subject must be a string… TypeError

php-src reference

  • ext/json/php_json.c — php_json_validate() (Z_PARAM_STR)
  • ext/pcre/php_pcre.c — php_pcre_split, php_pcre_grep, php_pcre_quote

Repro

./script/docker-exec.sh -- php bin/vm.php test/repro/maintainer_gap_json_validate_enum.php
./script/docker-exec.sh -- php bin/vm.php test/repro/maintainer_gap_preg_split_enum.php
./script/docker-exec.sh -- php bin/vm.php test/repro/maintainer_gap_preg_grep_enum.php
./script/docker-exec.sh -- php bin/vm.php test/repro/maintainer_gap_preg_quote_enum.php

Zend (any 8.x):

enum E: string { case A = 'x'; }
json_validate(E::A);   // TypeError
preg_split(E::A, '');  // TypeError
preg_grep(E::A, []);   // TypeError
preg_quote(E::A);      // TypeError

Implementation (PHP-in-PHP first)

  • VM: replace raw Variable::TYPE_STRING / VmReflection::stringArg() throws with VmString::coerceStringBuiltinArg() + EnumCaseSupport::isEnumCaseVariable() guard → TypeError with Zend-shaped messages
  • Files: ext/standard/json_validate.php, preg_split.php, preg_grep.php, preg_quote.php
  • JIT/AOT: mirror guards in JitStringBuiltinArg / per-builtin lowerers (JitStringArg::lower paths)
  • Do not coerce enum backing scalars

Verification

  • Repro scripts catch TypeError (not LogicException)
  • Add test/compliance/cases/stdlib/json_validate_enum_typeerror.phpt and preg_*_enum_typeerror.phpt
  • VM + JIT + AOT when issue scope requires all backends

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