Skip to content

Regression: preg_match()/preg_match_all() empty pattern — $matches array not NULL (re-#12688, ext/pcre/php_pcre.c) #17597

Description

@PurHur

Category

Regression · php-src-strict · stdlib

Problem

Closed in #12688 (2026-06-27) but master regressed: on empty-pattern compile failure Zend leaves by-ref $matches NULL; VM/JIT initialize it to an empty array.

Repro Zend 8.2 VM (2026-07-10) JIT (2026-07-10)
preg_match('', 'x', $m) after warning NULL array() array()
preg_match_all('', 'x', $m) after warning NULL array() array()

php-src reference

  • php/php-src ext/pcre/php_pcre.c — php_pcre_match_impl() leaves $matches unset/NULL when compile fails
  • Pure-PHP path: ext/standard/VmPregPure.php (pregMatch / pregMatchAll null-ovector branch sets $matches = [])

PHP implementation target

Repro

./script/docker-exec.sh -- bash -lc 'php bin/vm.php test/repro/maintainer_gap_preg_match_empty_pattern_matches_null.php'
./script/docker-exec.sh -- bash -lc 'php bin/jit.php test/repro/maintainer_gap_preg_match_empty_pattern_matches_null.php'

Done when

  • maintainer_gap_preg_match_empty_pattern_matches_null.php green on VM + JIT (+ AOT if wired)
  • Compliance guard under test/compliance/cases/stdlib/ for empty-pattern $matches NULL
  • php-src-strict; no php-compiler-strict shortcut

Activity

  1. added
    bugSomething isn't working
    phase-4:stdlibPhase 4 – stdlib for web apps
    area:vmVirtual machine
    implementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claim
    on Jul 10, 2026
  2. PurHur commented on Jul 10, 2026

    @PurHur
    OwnerAuthor

    claim: PHP Compiler STD Lib — starting this run

  3. PurHur commented on Jul 10, 2026

    @PurHur
    OwnerAuthor

    Merged in #17603.

    Root cause: VM preg_match() execute path wrote array() to by-ref $matches on false (compile failure). Zend leaves it unset/NULL; preg_match_all() already called $target->null().

    Fix: ext/standard/preg_match.php — use $target->null() on failure. JIT/AOT __compiler_preg_match_ex bridge was already correct.

    Verification:

    • php bin/vm.php test/repro/maintainer_gap_preg_match_empty_pattern_matches_null.php → ok
    • php bin/jit.php same repro → ok
    • vendor/bin/phpunit --filter preg_match_empty_pattern_matches_null → OK (VM + JIT compliance)
  4. PurHur commented on Jul 10, 2026

    @PurHur
    OwnerAuthor

    claim: PHP Compiler STD Lib Advanced — batch (ext/pcre #17597 regression from #17623)

  5. PurHur commented on Jul 10, 2026

    @PurHur
    OwnerAuthor

    Merged in #17673.

    Root cause: #17623 (ed0e44cb4) regressed #17603 by writing array() to by-ref $matches on all compile failures; Zend leaves the out-parameter unset.

    Fix: skip writing $matches when pregMatch* returns false (VM + JIT/AOT bridge).

    Verification: maintainer_gap_preg_match_empty_pattern_matches_null.php green on VM + JIT; duplicate-named repro still green.

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 machinebugSomething isn't workingimplementation-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