Skip to content

Language: print_r($x, true) as call arg remaps following string literal onto same temp (Zend/zend_vm_def.c) #24372

Description

@PurHur

Category

Language · php-src-strict · call/operand temps · print_r return

Problem

When print_r($value, true) is used directly as an argument to another call, the VM remaps the next string-literal argument onto the same temporary as the print_r return. Observable effect: str_contains / strpos / str_starts_with / str_ends_with / strstr behave as if the needle were a copy of the haystack (always a hit). Assigning the print_r result to a local first is fine; a variable needle is fine.

Probed 2026-07-28 vs Zend 8.2.32.

Repro Zend VM
str_contains(print_r([1,2,3], true), 'zzz') false true
str_contains(print_r([1,2,3], true), $n='zzz') false false
$s=print_r([1,2,3], true); str_contains($s,'zzz') false false
wrapper sc(print_r([1], true), 'zzz') seeing needle 'zzz' (len 3) needle === haystack print_r string (len 23)
strpos(print_r([1,2,3], true), 'zzz') false 0
str_starts_with(print_r([1,2,3], true), 'zzz') false true

php-src reference

PHP implementation target

Repro

./script/docker-exec.sh -- bash -lc 'php bin/vm.php -r '\''
var_export(str_contains(print_r([1,2,3], true), "zzz"));
echo "\n";
$n = "zzz";
var_export(str_contains(print_r([1,2,3], true), $n));
echo "\n";
'\'''

Expect: false / false. Actual: true / false.

Done when

  • Nested print_r(..., true) as haystack with literal needle matches Zend for str_contains / strpos / str_*_with / strstr
  • User-function wrapper sees distinct haystack vs needle values
  • Compliance guard under test/compliance/cases/; php-src-strict; no php-compiler-strict shortcut

Maintainer gate note (2026-07-28)

Pillar 1: user_release_ready: yes; north-star5-fast ok; inventory 6614/6614 inside readiness; host bootstrap-inventory --check still reports committed docs/bootstrap-inventory.md construct-flag drift for HelperRuntimeCache.php. Gen-0 provenance stale (known).

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:compilerCompiler / CFG / JITbugSomething isn't workingimplementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claimphase-3:aotPhase 3 – AOT deployment

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions