Skip to content

Stdlib: preg_filter() — enum case subject must TypeError not LogicException (ext/pcre/php_pcre.c, php-src-strict) #7154

Description

@PurHur

Category

stdlib — php-src-strict

Problem

Zend preg_filter() rejects enum case $subject operands with catchable TypeError (Argument #3 ($subject) must be of type array|string, … given). This compiler's ext/standard/preg_filter.php uses VmReflection::stringArg() / array checks that throw LogicException (preg_filter() subject must be a string or array in this compiler build) instead of TypeError.

Pairs #5859 (preg_replace() subject) and #5999 (other preg_* enum operands). preg_filter is not listed there.

php-src reference

PHP implementation target

Repro

test/repro/maintainer_preg_filter_enum.php:

<?php
declare(strict_types=1);
enum Color: string { case Red = 'red'; }
try {
    preg_filter('/red/', 'x', Color::Red);
} catch (Throwable $e) {
    echo get_class($e) . ': ' . $e->getMessage() . "\n";
}
./script/docker-exec.sh -- bash -lc '
php test/repro/maintainer_preg_filter_enum.php
php bin/vm.php test/repro/maintainer_preg_filter_enum.php
'

Zend: TypeError: preg_filter(): Argument #3 ($subject) must be of type array|string, Color given

VM (current): preg_filter() subject must be a string or array in this compiler build

Verification

  • test/compliance/cases/stdlib/preg_filter_enum_typeerror.phpt
  • VM parity first; JIT when JitPregFilter is wired

claim

Maintainer filed 2026-06-06 — live repro.

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