Skip to content

Array/hash equality (== and ===) is unsupported by the EIR backend #424

Description

@nahime0

Summary

Comparing two arrays with == or === is not supported by the EIR backend — for any array type (indexed or associative). This is a general gap, not tied to a specific array shape.

Reproduction

<?php
$a = [1, 2, 3];
var_dump($a === [1, 2, 3]);             // unsupported
var_dump(["x" => 1] === ["x" => 1]);   // unsupported
var_dump([1, 2, 3] == [1, 2, 3]);      // unsupported

elephc:

EIR backend error: unsupported EIR backend feature: strict_eq for PHP type Array(Int)
EIR backend error: unsupported EIR backend feature: strict_eq for PHP type AssocArray { key: Str, value: Int }
EIR backend error: unsupported EIR backend feature: loose_eq for PHP types Array(Int) and Array(Int)

PHP: true / true / true

Root cause

  • src/codegen_ir/lower_inst/comparisons.rs — the supported type combinations for strict_eq / loose_eq do not include Array(..) or AssocArray, so they fall into the "unsupported EIR backend feature" branch.
  • No runtime equality helpers exist (no __rt_array_eq / __rt_hash_eq).

Scope / semantics

PHP array comparison is non-trivial and recursive:

  • ===: same key/value pairs in the same order, with identical value types.
  • ==: same key/value pairs regardless of order, with value type-juggling.

Implementing this needs new dual-arch runtime routines plus lowering for both operators (and boxed-Mixed element comparison for heterogeneous arrays). Filing as a standalone feature.

Context

Found while reviewing the foreach Mixed-key array-write fix: a rebuilt Array(Mixed) could not be compared against an array literal — but the gap turned out to be general (plain [1,2,3] === [1,2,3] fails too), so it is unrelated to that fix and tracked separately here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:codegenTouches target-aware assembly or backend lowering.enhancementNew feature or requesttopic:arraysConcerns PHP arrays, hashes, indexing, or array operations.topic:php-compatChanges PHP compatibility or observable PHP semantics.

    Type

    No type

    Projects

    Status
    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions