Skip to content

Stdlib: array_find()/array_find_key()/array_all()/array_any() — PHP 8.4 $strict third parameter missing (ext/standard/array.c) #6949

Closed

Description

@PurHur

Category

stdlib · php-src-strict

Problem

PHP 8.4 added an optional $strict third parameter to array_find(), array_find_key(), array_all(), and array_any(). When $strict is true, the callback predicate uses === comparison semantics for matching; when false (default), loose == applies.

This compiler hard-codes arity at two arguments and throws LogicException when a third argument is passed — even though VM/JIT/AOT already implement the two-arg forms (#3073, capability matrix VM/JIT/AOT yes).

php-src reference

  • php/php-src ext/standard/array.c — array_find, array_find_key, array_all, array_any (strict flag forwarded to internal compare)
  • PHP 8.4 changelog / UPGRADING — new $strict parameter on array search helpers

Repro (failure today)

Save as test/repro/maintainer_array_find_strict.php:

<?php
$haystack = [1, '1', 2];

echo array_find($haystack, fn($v) => $v == 1) === 1 ? "1\n" : "miss\n";

try {
    array_find($haystack, fn($v) => $v == 1, true);
    echo "strict_ok\n";
} catch (Throwable $e) {
    echo get_class($e), ': ', $e->getMessage(), "\n";
}
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php test/repro/maintainer_array_find_strict.php
php bin/vm.php test/repro/maintainer_array_find_strict.php
'
Call Zend PHP 8.4+ VM today
array_find(..., fn, false) 1 (loose match) 1 OK
array_find(..., fn, true) false (no strict match) LogicException: exactly two arguments

Same arity gate on array_find_key, array_all, array_any.

Scope (this repo)

Path Work
ext/standard/array_find.php Accept optional 3rd bool $strict; delegate to shared helper
ext/standard/array_find_key.php, array_all.php, array_any.php Same
ext/standard/VmArrayValueCallback.php (or equivalent) Central strict vs loose predicate matching
JIT lowerers Mirror $strict in lib/JIT/Builtin/*ArrayFind* when present
Tests test/compliance/cases/stdlib/array_find_strict.phpt (+ siblings)

PHP-in-PHP: extend existing ext/standard handlers; no C runtime.

Strictness

php-src-strict — $strict must match Zend loose vs === predicate matching. Preserve enum-case objects in callbacks (#5638, #5722); do not coerce enum cases to backing scalars during strict checks.

Done when

  • All four functions accept optional $strict (default false) without LogicException
  • Repro: loose call returns 1; strict call returns false matching Zend PHP 8.4+
  • array_find_key / array_all / array_any strict semantics match php-src for shared test vectors
  • JIT/AOT parity on repro when JIT lowerers exist (or document VM-only deferral in matrix)
  • ./script/ci-fast.sh --filter array_find_strict green

Verification

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && ./vendor/bin/phpunit --filter array_find_strict'

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 6, 2026
  2. PurHur commented on Jun 6, 2026

    @PurHur
    OwnerAuthor

    claim: PHP Compiler STD Lib — starting this run

  3. PurHur commented on Jun 6, 2026

    @PurHur
    OwnerAuthor

    Unclaiming: php-src array_find/array_find_key/array_any/array_all accept exactly 2 parameters (basic_functions.stub.php ZEND_PARSE_PARAMETERS_START(2,2)); no $strict third arg in PHP 8.4. Issue spec appears to conflate with array_search/in_array. Re-file if targeting ArgumentCountError for excess args (#4145) or a future php-src change with upstream reference.

  4. PurHur commented on Jun 9, 2026

    @PurHur
    OwnerAuthor

    claim: PHP Compiler STD Lib — starting this run

  5. PurHur commented on Jun 9, 2026

    @PurHur
    OwnerAuthor

    Unclaiming: php-src array_find family accepts exactly 2 parameters (basic_functions.stub.php, ZEND_PARSE_PARAMETERS_START(2,2)); no $strict third arg in PHP 8.4 master. Prior unclaim stands — recommend closing unless upstream adds the parameter.

  6. PurHur commented on Jun 11, 2026

    @PurHur
    OwnerAuthor

    claim: PHP Compiler STD Lib — starting this run

  7. PurHur commented on Jun 11, 2026

    @PurHur
    OwnerAuthor

    Unclaiming: php-src array_find family accepts exactly 2 parameters (basic_functions.stub.php ZEND_PARSE_PARAMETERS_START(2,2)); no $strict third arg in PHP 8.4 master. Prior unclaim stands — recommend closing unless upstream adds the parameter.

  8. PurHur commented on Jun 14, 2026

    @PurHur
    OwnerAuthor

    claim: PHP Compiler STD Lib — starting this run

  9. PurHur commented on Jun 14, 2026

    @PurHur
    OwnerAuthor

    Unclaiming: php-src array_find family accepts exactly 2 parameters (basic_functions.stub.php ZEND_PARSE_PARAMETERS_START(2,2)); no $strict third arg in PHP 8.4 master. Prior unclaim stands — recommend closing unless upstream adds the parameter.

  10. PurHur commented on Jun 14, 2026

    @PurHur
    OwnerAuthor

    claim: PHP Runtime → PHP — starting this run (array_find family $strict third param, PHP 8.4 #6949). Supersedes #5796 triage (filter_var enum already returns false).

  11. PurHur commented on Jun 14, 2026

    @PurHur
    OwnerAuthor

    Triage: php-src master PHP_FUNCTION(array_find) still ZEND_PARSE_PARAMETERS_START(2, 2) — no $strict third parameter. Recommend closing as invalid spec; strict compare belongs in callback (or in_array parity).

  12. PurHur commented on Jun 14, 2026

    @PurHur
    OwnerAuthor

    claim: PHP Compiler STD Lib — starting this run

  13. PurHur commented on Jun 14, 2026

    @PurHur
    OwnerAuthor

    Unclaiming: php-src master array_find/array_find_key/array_all/array_any accept exactly 2 args (basic_functions.stub.php, ext/standard/array.c — merged RFC #14108). No $strict third parameter in Zend PHP 8.4. Issue spec appears to conflate with array_search($needle, $haystack, $strict). Recommend closing unless tracking a future php-src RFC.

  14. PurHur commented on Jun 16, 2026

    @PurHur
    OwnerAuthor

    claim: PHP Compiler STD Lib — starting this run

  15. PurHur commented on Jun 16, 2026

    @PurHur
    OwnerAuthor

    Unclaiming: php-src master array_find/array_find_key/array_all/array_any accept exactly 2 args (basic_functions.stub.php, ext/standard/array.c). No $strict third parameter in Zend PHP 8.4 — issue spec conflates with array_search. Switching to next eligible stdlib issue.

  16. PurHur commented on Jun 27, 2026

    @PurHur
    OwnerAuthor

    Maintainer unclaim 2026-06-27: stale claim: (>7d, no open PR). Issue remains implementation-ready for workers.

  17. PurHur commented on Jul 4, 2026

    @PurHur
    OwnerAuthor

    claim: worker-lane-c — starting this run

  18. PurHur commented on Jul 4, 2026

    @PurHur
    OwnerAuthor

    Merged via #16009.

    Verification (PHP 8.4 profile):
    ```bash
    ./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && export PHP_COMPILER_PROFILE=8.4 && php bin/vm.php test/repro/maintainer_array_find_strict.php'

    ok

    ./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && export PHP_COMPILER_PROFILE=8.4 && vendor/bin/phpunit --filter array_find_strict'

    OK (4 tests, 4 assertions)

    ```

    array_find / array_find_key / array_all / array_any now accept optional $strict using the same shared predicate helpers as array_all_key/array_any_key.

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