Skip to content

Runtime: ternary with function call in test/alternate — wrong branch value (Zend zend_compile.c parity) #3790

Description

@PurHur

Category

runtime

Problem

When a ternary (?:) uses a function call in the condition and again in the alternate arm, the VM prints the wrong branch value. A minimal getenv() repro shows the consequent string "unset" is replaced by the function name "getenv" even when the condition is true.

This breaks idiomatic env checks like getenv('VAR') === false ? 'unset' : getenv('VAR') used in bootstrap and CLI tooling.

php-src reference

Repro (failure today)

<?php
putenv('FOO=bar');
putenv('FOO'); // unset
echo getenv('FOO') === false ? 'unset' : getenv('FOO');
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && php bin/vm.php repro.php'
php repro.php
Runtime Output
Zend PHP 8.x unset
bin/vm.php getenv

Note: assigning to a temp works — $r = getenv('FOO'); echo $r === false ? 'unset' : 'val'; prints unset. Bug is specific to inline ternary with repeated call.

Scope (this repo)

Layer Path Notes
Compiler lib/Compiler.php Ternary/?? branch merge may reuse wrong operand slot for call results
VM lib/VM.php Verify TYPE_JUMP/assign phi for ternary arms
Tests test/compliance/cases/language/ternary_func_call.phpt getenv repro + generic foo() stub

Done when

Verification

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

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-2:languagePhase 2 – language features

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions