Skip to content

VM: sprintf with count() twice in one arg list yields 0 for first %d #36353

Description

@PurHur

Category

Bug: · silent wrong output · found by #36221 program corpus

Problem

$users = [["score" => 98.5], ["score" => 100.0], ["score" => 91.25]];
$sum = 0.0;
foreach ($users as $u) { $sum += $u["score"]; }
echo sprintf("n=%d avg=%.3f", count($users), $sum / count($users)), "\n";
output
Zend n=3 avg=96.583
VM n=0 avg=96.583

Standalone count($users) and sprintf(..., $n, $avg) with temps are fine — only the double count() in one call-arg list fails.

Repro

test/repro/i36221_sprintf_double_count.php

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && php test/repro/i36221_sprintf_double_count.php; php bin/vm.php test/repro/i36221_sprintf_double_count.php'

Done when

  • VM matches Zend on the repro
  • Case promoted to test/differential/cases/ and green under VM

Parent: #36221

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 claim

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions