Skip to content

Language: multi-arg call first ternary operand misbound when second operand is ternary (Zend/zend_compile.c) #15816

Description

@PurHur

Category

language · php-src-strict

Problem

When a function/method call has two or more arguments and both the first and second operands are ternary expressions, the VM/JIT lowering evaluates the first operand to the second ternary’s chosen value instead of the first ternary’s value. Zend evaluates each operand independently.

Repro Zend 8.2 (2026-07-04) VM (2026-07-04)
pair(true ? 'yes' : 'no', false ? 1 : 2) a=yes b=2 TypeError: pair(): Argument #1 ($a) must be of type string, int given
sprintf('%s-%d', true ? 'yes' : 'no', false ? 1 : 2) yes-2 2-2
var_dump($x === false ? 'false' : 'array', is_array($x) ? count($x) : null) string(5) "array" then int(14) int(14) then int(14)

Root cause is in call argument codegen (not var_dump()-specific) — user-defined typed functions show the same misbinding.

php-src reference

PHP implementation target

  • lib/Compiler.php — fix multi-arg call lowering when consecutive operands are Expr\Ternary
  • lib/VM.php / lib/JIT/ — verify VM and JIT agree; no new C runtime branches

Repro

./script/docker-exec.sh -- bash -lc 'php bin/vm.php test/repro/maintainer_gap_call_multiarg_ternary_misbind.php'
php test/repro/maintainer_gap_call_multiarg_ternary_misbind.php

Done when

  • pair(), sprintf(), and var_dump() repro outputs match Zend on VM
  • JIT path matches when JIT enabled for the same snippet
  • Compliance .phpt guard under test/compliance/cases/language/
  • php-src-strict; no php-compiler-strict shortcut

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:compilerCompiler / CFG / JITarea:vmVirtual machineenhancementNew feature or requestimplementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claimphase-2:languagePhase 2 – language features

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions