Skip to content

fix(collection): widen filter/reject for Laravel 13 compatibility - #3

Merged
agissept merged 1 commit into
masterfrom
fix/collection-l13-compat
Sep 11, 2026
Merged

agissept merged 1 commit into
masterfrom
fix/collection-l13-compat

Conversation

@agissept

Copy link
Copy Markdown
Member

Why

Spatie\BladeX\Laravel\Collection overrides filter(?Closure $callback = null) and reject($callback) with signatures narrower than the base Illuminate\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:

Declaration of Spatie\BladeX\Laravel\Collection::filter(?Closure $callback = null)
must be compatible with Illuminate\Support\Collection::filter(?callable $callback = null)

What

Widen both overrides to the least-restrictive form that is compatible with both the current base and the Laravel 13 base:

method before after
filter filter(?Closure $callback = null) filter($callback = null)
reject reject($callback) reject($callback = true)
  • filter → untyped. PHP does not accept callable as a widening of Closure (verified: ?callable overriding Closure is itself a fatal). Dropping the type (mixed) is the only signature that is a valid override against both filter(Closure) (4.2) and filter(?callable) (L13).
  • reject → = true default, so it's no longer stricter than either base.

Method bodies are unchanged — they already implement the ARRAY_FILTER_USE_BOTH value+key semantics, so behaviour is identical on both bases.

Compatibility

Verified against both bases:

  • 4.2 base (filter(Closure), reject($callback)) — loads (child widens).
  • Laravel 13 base (filter(?callable), reject($callback = true)) — loads + filter/reject return correct results.

This means the fix can be merged and deployed now, independently of the framework upgrade — no lockstep required.

🤖 Generated with Claude Code

… 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>
@agissept
agissept merged commit b45488e into master Sep 11, 2026
2 checks passed
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.

1 participant