Skip to content

Language: false array keys must coerce to 0 not LogicException (Zend/zend_hash.c) #5275

Closed

Description

@PurHur

Category

language

Problem

Using false as an array index must coerce to integer 0 (same as Zend). This compiler throws LogicException: Unknown index type 3 from lib/VM/HashTable.php because bool keys are not normalized before hashtable access.

Companion to #5269 (null → empty string); bool/false is a separate zend_hash coercion path.

php-src reference

Repro (failure today)

<?php
$a = [1, 2];
$a[false] = 3;
var_export($a);
echo "\n";
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php -r '"'"'$a=[1,2]; $a[false]=3; var_export($a); echo "\n";'"'"'
php bin/vm.php -r '"'"'$a=[1,2]; $a[false]=3; var_export($a); echo "\n";'"'"'
'
Engine Output
Zend PHP 8.2 array (0 => 3, 1 => 2)
bin/vm.php LogicException: Unknown index type 3

Also verify read path: $a = ['a' => 1]; var_export($a[false]); → NULL with warning on Zend.

Scope (this repo)

Area Files
VM lib/VM/HashTable.php — normalize bool index to int 0/1 before packed/hashtable ops
Compiler/JIT lib/JIT/Helper.php array offset lowering if bool keys reach native path
Tests test/compliance/cases/language/array_key_false.phpt

Implement coercion in PHP VM/JIT lowering; do not add new C branches in runtime/.

Done when

Links

Activity

  1. added
    enhancementNew feature or request
    area:vmVirtual machine
    implementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claim
    on Jun 3, 2026
  2. PurHur commented on Jun 3, 2026

    @PurHur
    OwnerAuthor

    claim: cursor-agent-lane-c — starting this run

  3. PurHur commented on Jun 3, 2026

    @PurHur
    OwnerAuthor

    Merged via #5312

    Fix: HashTable::normalizeIndexKey coerces bool keys to int 0/1; ErrorReporter::undefinedArrayKey uses the same normalization for warning text.

    Verification:

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 machineenhancementNew feature or requestimplementation-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