Skip to content

Language: $false[] = $v fatals — Zend promotes false to array like null (Zend/zend_execute.c) #22650

Description

@PurHur

Category

Language: · php-src-strict · auto-array promotion on append

Problem

Appending with [] = to null correctly promotes to an array. Appending to false must do the same (legacy Zend auto-conversion). The VM throws Error: Cannot use a scalar value as an array instead.

true correctly fatals on both engines; only false (and historically null) promote.

Repro Zend 8.2+ (2026-07-23) VM (2026-07-23)
$f=false; $f[]=1; array(0=>1) type array fatal scalar-as-array
$n=null; $n[]=1; array(0=>1) array(0=>1)
$t=true; $t[]=1; fatal scalar-as-array fatal scalar-as-array ✅

php-src reference

PHP implementation target

  • lib/VM.php (and shared dim-write / append lowering) — treat false like null when the write is [] = append
  • Mirror in lib/JIT/ dim-write if AOT/JIT diverge
  • Prefer PHP lowering; no new C runtime logic

Repro

./script/docker-exec.sh -- bash -lc 'php test/repro/maintainer_gap_false_append_promotes_array.php; php bin/vm.php test/repro/maintainer_gap_false_append_promotes_array.php'
# Zend: array ( 0 => 1, ) / array
# VM: Fatal Error Cannot use a scalar value as an array

Done when

  • $f=false; $f[]=1; yields [1] matching Zend on VM (and JIT/AOT when in scope)
  • true / int / float still Error
  • Compliance .phpt under test/compliance/cases/language/
  • php-src-strict; no php-compiler-strict shortcut

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