Skip to content

Stdlib: preg_quote() / quotemeta() — scalar-to-string coercion (ext/standard/string.c parity) #4294

Closed

Description

@PurHur

Category

stdlib

Problem

Zend coerces preg_quote() and quotemeta() subjects to string via _convert_to_string. This compiler rejects non-string operands with LogicException, diverging from php-src on scalar calls.

preg_quote() should also accept a null delimiter (coerced to empty string) per zend_parse_parameters optional string.

php-src reference

Repro (failure today)

<?php
var_export(preg_quote(42));
echo "\n";
var_export(preg_quote("a.b", null));
echo "\n";
var_export(quotemeta(1.5));
echo "\n";
php repro.php
# Zend: '42', 'a\\.b', '1\\.5'

tar -cf - --exclude=.git --exclude=.llvm . | docker run --rm -i -w /compiler php-compiler:22.04-dev bash -lc '
  tar -xf -; php bin/vm.php repro.php
'
# VM: LogicException preg_quote() subject must be a string...

Expected (Zend): as above
Actual: LogicException on first preg_quote() call

Scope

Module Path
VM ext/standard/preg_quote.php, ext/standard/quotemeta.php — reuse VmString::coerceOperand()
JIT JitQuotemeta, preg_quote JIT path — literal + runtime coercion
Tests test/compliance/cases/stdlib/preg_quote_quotemeta_coerce.phpt

Done when

  • Repro matches Zend on VM
  • preg_quote($s, null) uses empty delimiter like Zend
  • ./script/ci-fast.sh --filter preg_quote_quotemeta_coerce green

Related

Activity

  1. added
    enhancementNew feature or request
    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 Jun 2, 2026
  2. PurHur commented on Jun 11, 2026

    @PurHur
    OwnerAuthor

    claim: PHP Compiler STD Lib — starting this run

  3. PurHur commented on Jun 11, 2026

    @PurHur
    OwnerAuthor

    Unclaiming: preg_quote()/quotemeta() scalar coercion already green on master. VM repro prints '42', 'a.b', '1.5' matching Zend. coerceStringBuiltinArg + JitStringBuiltinArg in place. Recommend closing as duplicate unless repro differs.

  4. PurHur commented on Jul 19, 2026

    @PurHur
    OwnerAuthor

    unclaim: stale claim (>7 days, no open PR). Returning to implementation-ready queue for workers (maintainer sweep 2026-07-19).

  5. PurHur commented on Jul 19, 2026

    @PurHur
    OwnerAuthor

    unclaim: stale claim (>7 days, no PR). Returning to queue for workers.

  6. PurHur commented on Jul 19, 2026

    @PurHur
    OwnerAuthor

    unclaim: stale — last claim: was 2026-06-11 with no open PR and no further activity. Returning to implementation-ready queue for workers.

  7. PurHur commented on Jul 20, 2026

    @PurHur
    OwnerAuthor

    claim: worker-lane-b — starting this run

  8. PurHur commented on Jul 20, 2026

    @PurHur
    OwnerAuthor

    unclaim: scalar coercion already matches Zend on master (repro green). Switching to #20554.

  9. PurHur commented on Jul 20, 2026

    @PurHur
    OwnerAuthor

    claim: cursor-agent lane B — starting this run (4225 already green on master)

  10. PurHur commented on Jul 20, 2026

    @PurHur
    OwnerAuthor

    unclaim: already green on master (preg_quote/quotemeta coerce); working #5122 instead.

  11. PurHur commented on Jul 20, 2026

    @PurHur
    OwnerAuthor

    Verified resolved on master (2026-07-20).

    All done-when criteria pass:

    $ php bin/vm.php -r "var_export(preg_quote(42)); echo PHP_EOL;"
    '42'
    
    $ php bin/vm.php -r "var_export(preg_quote('a.b', null)); echo PHP_EOL;"
    'a\\.b'
    
    $ php bin/vm.php -r "var_export(quotemeta(1.5)); echo PHP_EOL;"
    '1\\.5'
    
    • preg_quote(42) coerces to "42" like Zend ✅
    • preg_quote("a.b", null) uses empty delimiter ✅
    • quotemeta(1.5) coerces scalar ✅
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