Skip to content

Stdlib: vsprintf() rejects inline array literal — LogicException not formatted string (ext/standard/sprintf.c) #9602

Description

@PurHur

Category

stdlib · compile lowering · php-src-strict

Problem

vsprintf('%d', [7]) fails at runtime when the second argument is an inline array literal, while the same values in a variable work. Zend returns the formatted string.

Call Zend VM today
vsprintf('%d', [7]) '7' LogicException: second argument must be an array
$a=[7]; vsprintf('%d',$a) '7' '7' (OK)

Same class of bug as literal-null / inline-[] mis-binding (#9305, #9563, #9349).

php-src reference

Repro

php test/repro/maintainer_vsprintf_inline_array.php
php bin/vm.php test/repro/maintainer_vsprintf_inline_array.php
php bin/vm.php -r '\$a=[7]; echo vsprintf("%d", \$a);'  # control: OK

Scope (PHP-in-PHP)

  • Fix builtin argument marshalling for inline array literals in lib/ compiler / VM call path
  • ext/standard sprintf family if argc guards assume non-literal arrays

Done when (php-src-strict)

  • Repro prints 7 on VM
  • Regression guard; JIT/AOT agree when sprintf builtins lowered

Links

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 appsstdlib

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions