Category
language · runtime · php-src-strict
Problem
Zend emits Warning: Undefined variable $name when a variable is read without being defined (and error_reporting includes E_WARNING). This compiler silently treats undefined locals as null in many fetch paths — no warning on stderr.
Verified 2026-06-20 (Docker php vs bin/vm.php):
| Expression |
Zend PHP 8.2 |
VM today |
echo $x; |
Warning, empty output |
no warning, empty output |
+$x / -$x |
Warning, 0 |
0 no warning ❌ |
$x + 1 |
Warning, 1 |
1 no warning ❌ |
(int)$x, (string)$x, (array)$x |
Warning + coerced value |
coerced, no warning ❌ |
$x ?? $y (both undefined) |
Warning on $y, result NULL |
NULL, no warning ❌ |
isset($x) / empty($x) |
no warning |
no warning ✓ (correct) |
Distinct from #10164 / #10096 (compact() key omission) and #273 (undefined array keys). This issue is local variable fetch semantics shared by VM/JIT/AOT.
php-src reference
Repro
<?php
declare(strict_types=1);
var_export(+$x);
echo "\n";
var_export($x ?? $y);
echo "\n";
var_export((string)$x);
echo "\n";
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php -r "var_export(+\$x); echo PHP_EOL; var_export(\$x ?? \$y); echo PHP_EOL;" 2>&1
php bin/vm.php -r "var_export(+\$x); echo PHP_EOL; var_export(\$x ?? \$y); echo PHP_EOL;" 2>&1
'
| Runtime |
Expected |
| Zend |
three Undefined variable warnings; values 0, NULL, '' |
| VM |
same warnings + values (today: values only) |
@ must suppress warnings (#9293 trigger_error path).
Scope (this repo)
| Path |
Work |
lib/VM/ErrorReporter.php |
undefinedVariable() — wire into fetch paths |
lib/VM.php |
operand fetch for unary/binary/cast/coalesce RHS |
lib/JIT/VarFetchHelper.php, lib/JIT/CoalesceHelper.php |
JIT must emit same warnings when not @-silenced |
| Tests |
test/compliance/cases/runtime/undefined_variable_read_warning.phpt |
PHP-in-PHP: warning text + guard in lib/VM/; JIT calls compiled PHP trampoline (see #10353 follow-up php-in-php issue).
Done when
Related
Category
language·runtime· php-src-strictProblem
Zend emits
Warning: Undefined variable $namewhen a variable is read without being defined (anderror_reportingincludesE_WARNING). This compiler silently treats undefined locals asnullin many fetch paths — no warning on stderr.Verified 2026-06-20 (Docker
phpvsbin/vm.php):echo $x;+$x/-$x00no warning ❌$x + 111no warning ❌(int)$x,(string)$x,(array)$x$x ?? $y(both undefined)$y, resultNULLNULL, no warning ❌isset($x)/empty($x)Distinct from #10164 / #10096 (
compact()key omission) and #273 (undefined array keys). This issue is local variable fetch semantics shared by VM/JIT/AOT.php-src reference
Zend/zend_execute.c—ZEND_FETCH_R,ZEND_CHECK_UNDEFINED_VARZend/zend_variables.c— undefined variable handlingZend/zend_operators.c—??evaluates RHS only when LHS is null/unsetRepro
0,NULL,''@must suppress warnings (#9293 trigger_error path).Scope (this repo)
lib/VM/ErrorReporter.phpundefinedVariable()— wire into fetch pathslib/VM.phplib/JIT/VarFetchHelper.php,lib/JIT/CoalesceHelper.php@-silencedtest/compliance/cases/runtime/undefined_variable_read_warning.phptPHP-in-PHP: warning text + guard in
lib/VM/; JIT calls compiled PHP trampoline (see #10353 follow-up php-in-php issue).Done when
isset/emptystill silent;@suppresses warnings./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && vendor/bin/phpunit --filter undefined_variable_read_warning'greenruntime/*.cRelated