Skip to content

Stdlib: sprintf()/printf() positional arguments — %1$s reordering (ext/standard/sprintf.c parity) #3631

Description

@PurHur

Category

stdlib

Problem

Zend sprintf() / printf() support positional arguments in the format string (%2$s, %1$d, …) so callers can reorder values without changing argument order. This compiler rejects those specifiers at runtime:

LogicException: sprintf() unsupported conversion specifier %2 in this compiler build

(ext/standard/VmSprintf.php).

php-src reference

Repro (failure today)

<?php
echo sprintf('%2$s %1$s', 'world', 'hello'), "\n";
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && php bin/vm.php repro.php'
/usr/bin/php repro.php   # Zend: hello world

This compiler: fatal in VmSprintf::format().

Additional cases for done-when:

printf('%1$d-%2$d', 10, 20);   // 10-20
sprintf('%2$.2f %1$s', 'pi', 3.14159); // 3.14 pi

Scope (this repo)

Module Path
VM formatter ext/standard/VmSprintf.php — parse %n$ prefix, remap arg index
Builtin wrappers ext/standard/sprintf_.php, printf if registered
JIT/AOT ext/standard/JitSprintf.php — delegate or document VM-only v1
Tests test/compliance/cases/stdlib/sprintf_positional.phpt
Matrix script/capability-matrix.php note on positional support

Done when

  • Repro prints hello world on VM matching Zend
  • Positional + width/precision specifiers (%2$.2f) match Zend on compliance fixtures
  • Invalid positional index raises Zend-compatible warning/error (not silent wrong output)
  • ./script/ci-fast.sh --filter sprintf_positional green

Related

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: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