Skip to content

Stdlib: sprintf()/printf()/vsprintf() object operands — LogicException not __toString coercion (ext/standard/spprintf.c) #13467

Closed

Description

@PurHur

Category

stdlib · php-src-strict

Problem

sprintf() / printf() / vsprintf() reject object operands for %s with LogicException: sprintf() %s requires a scalar value in this compiler build. Zend coerces via __toString() (or throws Error when conversion fails).

Concat ('x'.$obj.'y') and echo $obj already invoke __toString correctly.

php-src reference

Repro (verified 2026-06-29)

./script/docker-exec.sh -- bash -lc '
php test/repro/maintainer-parity-probes/probe_sprintf_object_tostring.php; echo ---;
php bin/vm.php test/repro/maintainer-parity-probes/probe_sprintf_object_tostring.php
php test/repro/maintainer-parity-probes/probe_printf_object_tostring.php; echo ---;
php bin/vm.php test/repro/maintainer-parity-probes/probe_printf_object_tostring.php
php test/repro/maintainer-parity-probes/probe_vsprintf_object.php; echo ---;
php bin/vm.php test/repro/maintainer-parity-probes/probe_vsprintf_object.php
'
Call Zend VM
sprintf('%s', $obj) 'obj' LogicException ❌
printf('%s', $obj) prints obj, returns 3 LogicException ❌
vsprintf('%s', [$obj]) 'obj' LogicException ❌

Scope (PHP-in-PHP first)

Layer Path
Builtin ext/standard/sprintf_.php, printf_.php, vsprintf_.php — use shared string-coercion helper (VmString::coerceStringBuiltinArg / JitStringBuiltinArg) before format dispatch
JIT lib/JIT/Builtin/ sprintf family must match VM
Tests test/compliance/cases/stdlib/sprintf_object_tostring.phpt

Done when (php-src-strict)

Verification

./script/docker-exec.sh -- php bin/vm.php test/repro/maintainer-parity-probes/probe_sprintf_object_tostring.php
./script/docker-exec.sh -- php bin/vm.php test/repro/maintainer-parity-probes/probe_vsprintf_object.php

Links

Activity

  1. added
    enhancementNew feature or request
    phase-4:stdlibPhase 4 – stdlib for web apps
    area:vmVirtual machine
    implementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claim
    on Jun 29, 2026
  2. PurHur commented on Jun 29, 2026

    @PurHur
    OwnerAuthor

    claim: PHP Runtime → PHP — batch (issues #13468 #13467)

  3. added a commit that references this issue on Jun 29, 2026
    2e1d0f4
  4. PurHur commented on Jun 29, 2026

    @PurHur
    OwnerAuthor

    Merged via #13481 — sprintf/printf/vsprintf %s coerces Stringable via VmString::coerceOperand; VM+JIT compliance green.

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 appsstdlib

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions