Skip to content

Regression: in_array()/array_search() enum needle — TypeError null haystack (re-#8796, ext/standard/array.c) #9702

Description

@PurHur

Category

stdlib · php-src-strict · regression

Problem

#8796 closed with enum needle/haystack parity, but VM regressed: in_array(E::A, [E::A, E::B]) and related calls now fatal with haystack null instead of returning booleans/keys. Zend still returns true / 0 as expected.

php-src reference

Repro

test/repro/maintainer_in_array_search_enum.php:

<?php
declare(strict_types=1);

enum E: int { case A = 1; case B = 2; }

var_export(in_array(E::A, [E::A, E::B]));
var_export(in_array(E::A, [E::A, E::B], true));
var_export(array_search(E::A, [E::A, E::B]));
var_export(in_array(1, [E::A], false));
./script/docker-exec.sh -- bash -lc 'php test/repro/maintainer_in_array_search_enum.php'
# Zend: true / true / 0 / true

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && php bin/vm.php test/repro/maintainer_in_array_search_enum.php'
# VM: Fatal TypeError haystack null on first in_array()
Call Zend VM today
in_array(E::A, [E::A, E::B]) true Fatal
in_array(E::A, ..., true) true (not reached)
array_search(E::A, ...) 0 (not reached)
in_array(1, [E::A], false) true (loose backing) (not reached)

Coordinate with #8898 for loose scalar-vs-case semantics once haystack wiring is restored.

Scope (this repo)

Area Path
Builtins ext/standard/in_array.php, array_search.php, shared array search helpers
Enum compare VM enum zval path — likely broken arg slot / null haystack after #9676 scalar regression

Done when

  • Full repro green under VM
  • Strict + loose enum cases covered
  • ./script/ci-fast.sh --filter InArray or compliance PHPT guard

Related

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

    IMPORTANTCritical patharea:vmVirtual machineenhancementNew 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