Skip to content

Stdlib: printf() — formatted output to stdout (ext/standard/formatted_print.c parity) #3681

Description

@PurHur

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

  • %d, %s, %f repro prints to stdout and returns correct byte length on VM
  • printf registered in capability matrix (VM yes)
  • ./script/ci-fast.sh --filter printf_basic green
  • No regression on existing sprintf() compliance tests

Verification

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && vendor/bin/phpunit --filter printf_basic'

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