Skip to content

PHP85-138 Accept array callables to non-public methods in getBehavior() again - #52

Merged
alenarmona merged 1 commit into
masterfrom
fix-array-callable-strategy
Oct 28, 2026
Merged

alenarmona merged 1 commit into
masterfrom
fix-array-callable-strategy

Conversation

@alenarmona

Copy link
Copy Markdown
Contributor

Accept array callables to non-public methods in getBehavior() again

6.0.0 typed Builder::getBehavior()'s first parameter as string|callable. defaultBehavior() and Manager::invoke() pass their strategy through that parameter, so a [$this, 'protectedMethod'] array is rejected by PHP before it reaches the branch that binds it into a closure (callable is scope-sensitive: a protected method is not callable from the Builder's scope). Swivel 4 accepted it, this repo's README documents it (defaultBehavior([$this, 'renderOldView']) with a protected renderOldView), and admin, public and service all use it.

TypeError: Zumba\Swivel\Builder::getBehavior(): Argument #1 ($slug) must be of type callable|string, array given, called in src/Builder.php on line 102

Change

  • Builder::getBehavior() and BuilderInterface::getBehavior(): first parameter is string|callable|array, so the existing bindTo() branch handles the array as in 4.x. No other behavior change.
  • BuilderTest: two regression tests (getBehavior() with a protected array callable as the strategy; defaultBehavior() with a protected target through execute()). Both fail on 6.0.1 and pass here. Suite: 173 tests, PSR-2 clean.

Who is affected on 6.0.1

  • admin (swivel-cake 3.0.0 → swivel 6.0.1): TrainingsController::membershipFees() is private and is the default of ZinRefactor.Benefit.ReplaceRole; it throws whenever that flag is off for the bucket.
  • public (same versions, deploying): its 27 array-callable defaults all target public methods, so no failure today, but the README pattern would break on first use.
  • service via zumba/primer: 17 production sites target protected methods, which is what blocks primer from requiring swivel 6 (zumba/primer#349).

Suggested tag: v6.0.2. swivel-cake already allows it (^6.0.1); admin and public pick it up with composer update zumba/swivel.

🤖 Generated with Claude Code

6.0.0 typed Builder::getBehavior()'s first parameter as string|callable.
defaultBehavior() and Manager::invoke() pass their strategy through that
parameter, so a [$this, 'protectedMethod'] array, which is not callable
from the Builder's scope, is rejected by PHP before reaching the branch
that binds it into a closure. Swivel 4 accepted it, swivel-cake's README
documents it, and admin, public and service all use it.

Widen the parameter to string|callable|array so the existing bindTo()
branch handles the array as before. Two regression tests fail on 6.0.1
with "Argument #1 ($slug) must be of type callable|string, array given".

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@alenarmona alenarmona changed the title Accept array callables to non-public methods in getBehavior() again PHP85-138 Accept array callables to non-public methods in getBehavior() again Oct 28, 2026
@alenarmona
alenarmona merged commit 63a8c34 into master Oct 28, 2026
6 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.

2 participants