Skip to content

Stdlib: sprintf()/printf()/vsprintf() — enum case operands must Error not coerce (ext/standard/sprintf.c) #8777

Closed

Description

@PurHur

Category

stdlib

Problem

Formatted-output builtins must reject enum case operands the same way Zend does. With %s, php-src throws Error (Object of class E could not be converted to string). VM silently coerces backed enum cases to backing strings and formats them.

php-src reference

Repro

test/repro/maintainer_sprintf_enum_operand.php:

php test/repro/maintainer_sprintf_enum_operand.php
./script/docker-exec.sh -- bash -lc 'php bin/vm.php test/repro/maintainer_sprintf_enum_operand.php'
Call Zend VM today
sprintf('%s', ES::X) Error NO_ERROR → 'hi'
vsprintf('%s', [ES::X]) Error NO_ERROR
printf('%s', ES::X) Error NO_ERROR

Scope

  • ext/standard/sprintf.php, printf.php, vsprintf.php, vfprintf.php
  • PHP lowering in lib/JIT/Builtin/ — no new C runtime branches
  • JIT/AOT must match VM

Done when

  • All three repro lines throw Error on VM (and JIT/AOT when in scope)
  • ./script/ci-fast.sh --filter SprintfEnum or targeted compliance PHPT green
  • php-src-strict

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 15, 2026
  2. PurHur commented on Jun 16, 2026

    @PurHur
    OwnerAuthor

    claim: PHP Compiler STD Lib — starting this run

  3. PurHur commented on Jun 16, 2026

    @PurHur
    OwnerAuthor

    Unclaiming: sprintf/printf/vsprintf enum %s operands already throw Error on master (VmSprintf::argToString + compliance test sprintf_enum_case.phpt green). VM repro matches Zend for ES::X %s. Recommend closing as duplicate unless repro differs.

  4. PurHur commented on Jul 18, 2026

    @PurHur
    OwnerAuthor

    Already fixed — closing (lane C audit 2026-07-18)

    Verified on current master — Zend PHP and php bin/vm.php both throw Error: Object of class ES could not be converted to string for sprintf/vsprintf/printf('%s', ES::X). Matches prior unclaim note (VmSprintf::argToString + sprintf_enum_case.phpt).

    No PR needed.

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