Skip to content

Regression: array_search() strict — int needle returns false not haystack index (re-#8886, ext/standard/array.c) #16316

Description

@PurHur

Category

Regression · php-src-strict · stdlib

Problem

In strict mode, an int needle must match an int haystack element by identity/type — not an enum case with the same backing value. When the matching scalar appears at index 0 before an enum case, Zend returns 0; the VM returns false.

Repro Zend 8.2 VM (2026-07-05)
array_search(1, [1, E::A], true) with enum E: int { case A = 1; } 0 false

Closed #8886 tracked the inverse ordering; this ordering still diverges after close.

php-src reference

PHP implementation target

  • ext/standard/ array_search lowering — shared strict equality guard with in_array(); ensure scalar int matches int element before enum-case handling
  • lib/VM.php / lib/JIT/ — same semantics when both backends are in scope

Repro

./script/docker-exec.sh -- bash -lc 'php bin/vm.php test/repro/maintainer_gap_array_search_strict_scalar_order.php'
./script/docker-exec.sh -- bash -lc 'php test/repro/maintainer_gap_array_search_strict_scalar_order.php'

Done when

  • VM prints 0 matching Zend for the repro (JIT/AOT if array_search is lowered there)
  • Compliance .phpt guard under test/compliance/cases/stdlib/
  • 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 workingenhancementNew feature or requestimplementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claimphase-4:stdlibPhase 4 – stdlib for web appsstdlib

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions