Description
A by-reference foreach over an indexed array can leave the array in a bad runtime state for a later by-value foreach over the same array.
PHP 8.4.19 prints the expected mutated values. The current Elephc tree compiles successfully, but the generated binary exits with SIGSEGV.
Minimal repro
<?php
$a = [1, 2, 3];
foreach ($a as &$v) { $v *= 2; }
unset($v);
foreach ($a as $v) { echo $v; }
Steps to reproduce
- Save the repro as
main.php.
- Run
php -d display_errors=1 -d error_reporting=E_ALL main.php.
- Compile with Elephc and run the produced binary.
Expected behavior
PHP output:
The Elephc-compiled binary should print the same output and exit 0.
Actual behavior
- PHP 8.4.19: stdout
246, exit 0
- Elephc current tree: compile succeeds, binary exits
SIGSEGV (-11) with no stdout/stderr
Direct indexed reads after the by-ref loop still work:
<?php
$a = [1, 2, 3];
foreach ($a as &$v) { $v *= 2; }
unset($v);
echo $a[0], $a[1], $a[2];
That prints 246 under Elephc, so the crash seems specific to the later by-value foreach path.
Environment
- Elephc crate version during build:
0.23.7
- Git commit:
09cb0523
- OS: macOS arm64
- PHP baseline:
PHP 8.4.19 (cli)
Description
A by-reference
foreachover an indexed array can leave the array in a bad runtime state for a later by-valueforeachover the same array.PHP 8.4.19 prints the expected mutated values. The current Elephc tree compiles successfully, but the generated binary exits with
SIGSEGV.Minimal repro
Steps to reproduce
main.php.php -d display_errors=1 -d error_reporting=E_ALL main.php.Expected behavior
PHP output:
The Elephc-compiled binary should print the same output and exit
0.Actual behavior
246, exit0SIGSEGV(-11) with no stdout/stderrDirect indexed reads after the by-ref loop still work:
That prints
246under Elephc, so the crash seems specific to the later by-valueforeachpath.Environment
0.23.709cb0523PHP 8.4.19 (cli)