Skip to content

Stdlib: preg_grep() — enum case pattern operand must TypeError not silent pass (ext/pcre/php_pcre.c) #9025

Description

@PurHur

Category

stdlib · php-src-strict

Problem

preg_grep() argument #1 ($pattern) must be string. Passing a backed enum case must throw TypeError with Zend's message. This compiler either coerces silently or prints uncaught without surfacing the expected TypeError.

Distinct from closed #5639 (enum case array values in haystack).

php-src reference

Repro

test/repro/maintainer_gap_preg_grep_enum.php (in tree):

<?php
enum E: string { case A = 'x'; }
try {
    preg_grep(E::A, []);
    echo "uncaught\n";
} catch (TypeError $e) {
    echo 'TypeError: ', $e->getMessage(), "\n";
}
php test/repro/maintainer_gap_preg_grep_enum.php
php bin/vm.php test/repro/maintainer_gap_preg_grep_enum.php
Output
Zend TypeError: preg_grep(): Argument #1 ($pattern) must be of type string, E given
VM today uncaught

Scope (this repo)

Path Work
ext/standard/ or lib/VM/ preg_grep builtin VmString::coerceStringBuiltinArg / enum guard before pattern use
lib/JIT/Builtin/ Mirror TypeError for enum pattern operand
Tests extend test/compliance/cases/stdlib/preg_grep_enum_typeerror.phpt

Done when

  • VM throws TypeError matching Zend message class + text
  • JIT/AOT agree when in scope
  • ./script/ci-fast.sh --filter preg_grep_enum green

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