Skip to content

Language: $a[missing]++ omits Undefined array key Warning — Zend warns then treats as null (zend_execute.c) #30078

Description

@PurHur

Category

Language · php-src-strict · dim pre/post inc on undefined key

Problem

$a[0]++ when key 0 is undefined must emit Warning: Undefined array key 0, then treat the missing value as null and store 1. VM/JIT silently produce 1 with no Undefined array key Warning (final array matches).

Also visible after false→array auto-convert Deprecated: Zend still warns on the missing key; VM/JIT only show the Deprecated.

Probed 2026-08-11 — php:8.4-cli 8.4.24 vs PHP_COMPILER_PROFILE=8.4 @ a0e79a9651.

Repro Zend 8.4.24 VM / JIT
$x=[]; $x[0]++; Warning: Undefined array key 0 then done / [0=>1] no Warning; done / [0=>1]
$x=false; $x[0]++; Deprecated: Automatic conversion of false to array… and Warning: Undefined array key 0 then [0=>1] Deprecated only; [0=>1]

php-src reference

PHP implementation target

  • Dim inc/dec fetch: emit Undefined array key Warning (E_WARNING) before coercing missing to null
  • lib/VM/ + JIT dim-inc/dec paths
  • PHP-in-PHP; no new runtime/*.c

Repro

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
export PHP_COMPILER_PROFILE=8.4
printf "%s\n" "<?php
\$x=[];
try { \$x[0]++; echo \"done\n\"; var_export(\$x); echo PHP_EOL; } catch (Throwable \$e) {
  echo get_class(\$e), \": \", \$e->getMessage(), PHP_EOL;
}
" >/tmp/dim_inc_undef.php
php -d error_reporting=E_ALL -d display_errors=1 bin/vm.php /tmp/dim_inc_undef.php
php -d error_reporting=E_ALL -d display_errors=1 bin/jit.php /tmp/dim_inc_undef.php
'

Done when

  • VM + JIT emit Undefined array key Warning for $a[missing]++ / -- (empty array case)
  • After false→array Deprecated, the same Warning still appears
  • Final value remains 1 (php-src-strict)
  • Compliance .phpt under test/compliance/cases/
  • 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:vmVirtual machinebugSomething isn't workingimplementation-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