Category
stdlib / runtime
Problem
sprintf() / vsprintf() are implemented, but printf() is missing — formatted writes to stdout fail at link/call time. Zend printf() shares the formatted_print.c engine with sprintf() and returns the number of bytes written.
php-src reference
Repro (today)
<?php
$n = printf("%d %s\n", 42, 'ok');
var_dump($n);
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && php bin/vm.php -r "\$n = printf(\"%d %s\\n\", 42, \"ok\"); var_dump(\$n);"'
php -r '$n = printf("%d %s\n", 42, "ok"); var_dump($n);'
| Engine |
stdout |
Return |
| Zend |
42 ok\n |
int(7) (byte count) |
| This compiler |
— |
LogicException: Call to undefined function printf() |
Error path (subset)
<?php
printf('%'); // Zend: Warning + false; document behavior
Scope (this repo)
| Module |
Path |
| VM |
ext/standard/printf.php — delegate formatting to existing sprintf/VmString helper, echo/stdout write, return length |
| Module |
ext/standard/Module.php |
| JIT |
optional phase 2 — reuse sprintf JIT pieces if any |
| Tests |
test/compliance/cases/stdlib/printf_basic.phpt |
| Matrix |
script/capability-matrix.php |
Implementation hint: mirror fprintf() design in #3301 but target SAPI stdout instead of stream resource.
Done when
Verification
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && vendor/bin/phpunit --filter printf_basic'
Related
Category
stdlib/runtimeProblem
sprintf()/vsprintf()are implemented, butprintf()is missing — formatted writes to stdout fail at link/call time. Zendprintf()shares theformatted_print.cengine withsprintf()and returns the number of bytes written.php-src reference
ext/standard/formatted_print.c—PHP_FUNCTION(printf)→ internalphp_printfext/standard/sprintf.c— shared format parser (if split in tree)fprintf()stream variant — Stdlib: fprintf() — formatted write to stream (ext/standard/formatted_print.c parity) #3301%1$s— Stdlib: sprintf()/printf() positional arguments — %1$s reordering (ext/standard/sprintf.c parity) #3631Repro (today)
42 ok\nint(7)(byte count)LogicException: Call to undefined function printf()Error path (subset)
Scope (this repo)
ext/standard/printf.php— delegate formatting to existingsprintf/VmStringhelper,echo/stdout write, return lengthext/standard/Module.phpsprintfJIT pieces if anytest/compliance/cases/stdlib/printf_basic.phptscript/capability-matrix.phpImplementation hint: mirror
fprintf()design in #3301 but target SAPI stdout instead of stream resource.Done when
%d,%s,%frepro prints to stdout and returns correct byte length on VMprintfregistered in capability matrix (VM yes)./script/ci-fast.sh --filter printf_basicgreensprintf()compliance testsVerification
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && vendor/bin/phpunit --filter printf_basic'Related
%1$s(sprintf/printf family)fprintf()vsprintf()/sscanf()