Skip to content

Language: undefined variable E_WARNING missing on read — casts/unary/arithmetic/?? RHS silent (Zend/zend_execute.c) #10358

Description

@PurHur

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

  • Repro emits Zend-matching Undefined variable warnings on VM (and JIT when in scope)
  • isset/empty still silent; @ suppresses warnings
  • ./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && vendor/bin/phpunit --filter undefined_variable_read_warning' green
  • No new logic in runtime/*.c

Related

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

    IMPORTANTCritical patharea:vmVirtual machineenhancementNew feature or requestimplementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claimphase-2:languagePhase 2 – language featuresstdlib

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions