Skip to content

Stdlib: array_find()/array_find_key() must preserve enum cases in predicate callbacks (ext/standard/array.c) #5638

Closed

Description

@PurHur

Category

stdlib

Problem

array_find() / array_find_key() exist on this compiler (PHP 8.4 subset) and already return enum cases from the array when the predicate matches. The remaining gap is callback operand parity: predicate closures must receive enum case objects, not backed scalars, and strict identity (===) must match Zend.

php-src reference

Repro

<?php
enum E: int { case A = 1; case B = 2; }
$found = array_find([E::A, E::B], function ($v) {
    if (!($v instanceof E)) {
        throw new RuntimeException('expected enum object, got ' . get_debug_type($v));
    }
    return $v === E::B;
});
var_dump($found);
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php repro.php 2>/dev/null || echo "Zend skip: array_find needs PHP 8.4"
./phpc run repro.php
'
Runtime $found Callback $v type
Zend 8.4+ E::B E object
VM must not throw; enum(E::B) object, not int(2)

Scope (this repo)

Area Path
Stdlib ext/standard/array_find.php, array_find_key.php
VM lib/VM.php — callback arg marshalling for enum cases
JIT/AOT #4009 phase 2 — closure callbacks

Done when

  • Repro completes without RuntimeException; var_dump shows enum(E::B)
  • array_find_key sibling test with same enum array
  • ./script/ci-fast.sh --filter array_find_enum green

Related

Activity

  1. added
    enhancementNew feature or request
    phase-4:stdlibPhase 4 – stdlib for web apps
    area:vmVirtual machine
    implementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claim
    on Jun 4, 2026
  2. PurHur commented on Jun 14, 2026

    @PurHur
    OwnerAuthor

    claim: PHP Compiler STD Lib — starting this run

  3. PurHur commented on Jun 14, 2026

    @PurHur
    OwnerAuthor

    Merged via #8515.

    What changed: ArrayFindHelper LLVM control-flow fixes (correct BasicBlock merge target + builder positioning) so array_find() with closure callbacks on enum arrays compiles through AOT lint. Added VM/JIT compliance PHPT (array_find_enum*, array_find_key_enum) and AOT compile-only probe.

    Verification (green):

    • VM/JIT repro test/repro/array_find_enum.php → enum(E::B)
    • php bin/compile.php -l test/repro/array_find_enum.php → exit 0
    • vendor/bin/phpunit --filter 'array_find_enum|array_find_key_enum|ArrayFind' → OK

    Follow-up: user-defined enum AOT execute still segfaults (var_dump(E::B) → unknown()); that is a broader user-enum runtime gap, not array_find callback marshalling (VM/JIT parity is green).

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-4:stdlibPhase 4 – stdlib for web apps

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions