Skip to content

Update StandardFilters::map() to skip non-object callables - #244

Merged
sanmai merged 1 commit into
kalimatas:masterfrom
sanmai:fix/StandardFilters-map
Nov 5, 2026
Merged

sanmai merged 1 commit into
kalimatas:masterfrom
sanmai:fix/StandardFilters-map

Conversation

@sanmai

@sanmai sanmai commented Nov 5, 2026 •

Copy link
Copy Markdown
Collaborator

The map filter used is_callable() to decide if it must invoke an element. This check accepts closures and invokable objects. It also accepts function name strings, 'Class::method' strings, among others.

With this change, map invokes only objects that are callable: closures and objects with an __invoke() method.

This change affects only code that gives map string or array callables through template variables. Such elements now resolve to null.

Example of affected code:

$template->parse('{{ items | map: "name" | join: "," }}');
$template->render(['items' => ['Foo::bar', [$service, 'label']]]);

To keep the previous result, convert the callables to closures:

$template->render(['items' => [Foo::bar(...), $service->label(...)]]);
  • Earlier versions did not document or test string and array callables in map.
  • The tests have used closures since the filter was added.

@sanmai
sanmai merged commit fa83ee4 into kalimatas:master Nov 5, 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.

1 participant