Skip to content

Stdlib: vsprintf() and sscanf() — formatted I/O (ext/standard/sprintf.c parity) #3190

Description

@PurHur

Category

stdlib

Problem

sprintf() exists, but vsprintf() (format + array of args) and sscanf() (parse string into variables) are missing. Zend stdlib and many PECL-style snippets depend on them; sscanf is the inverse of sprintf for simple parsers.

php-src reference

Repro (failure today)

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && php bin/vm.php -r '"'"'echo vsprintf("%s-%d", ["a", 3]);'"'"''
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && php bin/vm.php -r '"'"'$n = 0; sscanf("42", "%d", $n); echo $n;'"'"''

Expected (Zend): a-3 and 42
Actual: undefined function for vsprintf / sscanf.

Scope (this repo)

  • ext/standard/vsprintf.php, ext/standard/sscanf.php
  • VM: host vsprintf / sscanf with reference-parameter lowering for $n out-args (see Language: Reference assignment and by-ref parameters #140 by-ref)
  • ext/standard/Module.php
  • JIT: reuse existing sprintf JIT helpers where possible, or VM-only v1
  • test/compliance/cases/stdlib/vsprintf_basic.phpt, sscanf_int.phpt
  • script/capability-matrix.php

Done when

  • vsprintf('%s', ['ok']) === 'ok' on VM
  • sscanf('10 20', '%d %d', $a, $b) assigns $a=10, $b=20 (VM reference args)
  • Format/arg count mismatch warnings match Zend smoke tests
  • Matrix documents VM/JIT/AOT columns

Labels

stdlib, phase-4:stdlib, area:vm, implementation-ready

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