feat: in_array() accepts the optional strict (3rd) argument#464
Merged
nahime0 merged 5 commits intoJul 7, 2026
Merged
Conversation
`in_array($needle, $haystack, true)` failed to compile ("in_array() takes
exactly 2 arguments") — the builtin capped arity at 2 via `max_args: 2` and
lower_in_array asserted exactly 2 operands. Remove the cap and accept 2-3 args.
lower_in_array's per-type comparison (int/float/bool by value, string by
byte-equality) is already type-specific, so for the homogeneously-typed arrays
real code uses `in_array(..., true)` with, the result already matches strict
`===` membership (byte-parity verified: string[] + int[], present + absent).
The strict flag itself is not separately consulted — a heterogeneous-array
type-juggling distinction would need it (documented follow-up). AIC EC-2 (illegalstudio#485).
(cherry picked from commit f55a446)
Member
|
I'll take over this to implement the strict / loose comparison. We have some helpers that we can reuse (like __rt_str_loose_eq). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
in_array($needle, $haystack, true)failed to compile — "in_array() takes exactly 2 arguments". The builtin capped arity at 2 (max_args: 2) andlower_in_arrayasserted exactly 2 operands.Fix
Remove the cap; accept 2–3 args.
lower_in_array's per-type comparison (int/float/bool by value, string by byte-equality) is already type-specific, so for homogeneously-typed arrays the result matches strict===membership (byte-parity verified: string[] + int[], present + absent). Thestrictflag itself is not separately consulted yet — a heterogeneous-array type-juggling distinction would need it (documented follow-up). Builds standalone onmain.