Skip to content

feat: in_array() accepts the optional strict (3rd) argument#464

Merged
nahime0 merged 5 commits into
illegalstudio:mainfrom
chadmandoo:upstream-pr/in-array-strict-arg
Jul 7, 2026
Merged

feat: in_array() accepts the optional strict (3rd) argument#464
nahime0 merged 5 commits into
illegalstudio:mainfrom
chadmandoo:upstream-pr/in-array-strict-arg

Conversation

@chadmandoo

Copy link
Copy Markdown
Contributor

What

in_array($needle, $haystack, true) failed to compile — "in_array() takes exactly 2 arguments". The builtin capped arity at 2 (max_args: 2) and lower_in_array asserted 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). The strict flag itself is not separately consulted yet — a heterogeneous-array type-juggling distinction would need it (documented follow-up). Builds standalone on main.

chadmandoo and others added 2 commits July 5, 2026 14:30
`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)
@nahime0 nahime0 self-requested a review July 7, 2026 09:38
@nahime0

nahime0 commented Jul 7, 2026

Copy link
Copy Markdown
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).

@nahime0 nahime0 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All done, ready to merge

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants