fix(collection): widen filter/reject for Laravel 13 compatibility - #3
Merged
Merged
Conversation
… Collection The custom Collection overrides `filter(?Closure $callback = null)` and `reject($callback)` with signatures narrower than the base Collection. Under the Laravel 13 upgrade the base becomes `filter(?callable $callback = null)` and `reject($callback = true)`, which makes these overrides fatal at class load: PHP LSP forbids a child from narrowing a parameter type or making an optional parameter required. Widen both to the least-restrictive form compatible with BOTH the current 4.2-era base (`filter(Closure)`, `reject($callback)`) and the Laravel 13 base: - filter: drop the parameter type entirely. PHP does not accept `callable` as a widening of `Closure`, so untyped (mixed) is the only type that is a valid override against both bases. - reject: add the `= true` default. Method bodies are unchanged (they already implement the value+key filter semantics), so behaviour is identical on both bases. This lets the package be merged and deployed independently of the framework upgrade. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
Why
Spatie\BladeX\Laravel\Collectionoverridesfilter(?Closure $callback = null)andreject($callback)with signatures narrower than the baseIlluminate\Support\Collection. That's fine against the current 4.2-era base, but the L42x → Laravel 13 upgrade changes the base to:filter(?callable $callback = null)reject($callback = true)PHP's LSP forbids a child from narrowing a parameter type or making an optional parameter required, so under L13 both overrides become a fatal error at class load:
What
Widen both overrides to the least-restrictive form that is compatible with both the current base and the Laravel 13 base:
filterfilter(?Closure $callback = null)filter($callback = null)rejectreject($callback)reject($callback = true)callableas a widening ofClosure(verified:?callableoverridingClosureis itself a fatal). Dropping the type (mixed) is the only signature that is a valid override against bothfilter(Closure)(4.2) andfilter(?callable)(L13).= truedefault, so it's no longer stricter than either base.Method bodies are unchanged — they already implement the
ARRAY_FILTER_USE_BOTHvalue+key semantics, so behaviour is identical on both bases.Compatibility
Verified against both bases:
filter(Closure),reject($callback)) — loads (child widens).filter(?callable),reject($callback = true)) — loads +filter/rejectreturn correct results.This means the fix can be merged and deployed now, independently of the framework upgrade — no lockstep required.
🤖 Generated with Claude Code