Skip to content

Stdlib: preg_replace() array $pattern/$replacement overload — TypeError not AbA (ext/pcre/php_pcre.c) #10808

Description

@PurHur

Summary

Zend supports preg_replace() with array $pattern and $replacement arguments (parallel pattern/replacement pairs). php-compiler VM rejects array $pattern with TypeError: Argument #1 ($pattern) must be of type string.

Distinct from #9363 (array subject replacement semantics).

php-src reference

  • ext/pcre/php_pcre.cphp_pcre_replace_impl() array-pattern branch

Repro

<?php
declare(strict_types=1);

echo preg_replace(['/a/'], ['A'], 'aba'); // Zend: AbA — VM: TypeError

Committed repro: test/repro/maintainer_gap_preg_replace_array_pattern.php

./script/docker-exec.sh -- php test/repro/maintainer_gap_preg_replace_array_pattern.php      # PASS
./script/docker-exec.sh -- php bin/vm.php test/repro/maintainer_gap_preg_replace_array_pattern.php  # TypeError

Expected (php-src-strict)

Implementation hints (PHP-in-PHP)

  • ext/standard / PCRE builtin in ext/ + VM lowering (lib/VM/Builtin/ or dedicated PCRE helper).
  • Prefer PHP implementation shared by VM/JIT; shrink any C regex helpers rather than extending runtime/.

Done when

  • Repro green on VM.
  • Targeted test; JIT/AOT if those paths expose preg_replace.

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 appsstdlib

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions