merged branch fabpot/callables-everywhere (PR #905)
authorFabien Potencier <fabien.potencier@gmail.com>
Tue, 11 Dec 2012 11:12:31 +0000 (12:12 +0100)
committerFabien Potencier <fabien.potencier@gmail.com>
Tue, 11 Dec 2012 11:12:31 +0000 (12:12 +0100)
commitb22c076fc2eee4ba641b7ec20d3f3023da290ef0
treef3885d2c902d858c00be34aa6539a011c06376ea
parent4b359deec003c9dfcf4d1e5fd06097b582583e7a
parent1918edefa937b81233087aa79297e54ea0462f9b
merged branch fabpot/callables-everywhere (PR #905)

This PR was merged into the master branch.

Commits
-------

1918ede added the ability to use any PHP callable to define filters, functions, and tests

Discussion
----------

added the ability to use any PHP callable to define filters, functions, and tests

Everything is in the title.

---------------------------------------------------------------------------

by Tobion at 2012-11-18T13:25:51Z

Are filters etc. slower when defined as closures (instead of function definitions)?

---------------------------------------------------------------------------

by fabpot at 2012-11-18T13:30:47Z

@Tobion No, it does not matter how they are defined. Speed will be the same. A function is probably slightly faster as we can optimize the compiled template more than when it is an anonymous function where we need to use `call_user_func`.

---------------------------------------------------------------------------

by Tobion at 2012-11-18T13:40:17Z

This slight difference is what I questioned. On top of that, PHP can also not precompile those `call_user_func` I guess (e.g. when using APC). But it's probably not a big deal.
Since you have many examples in the doc with closures, I hope that it does not become the standard way for people to define custom functions.
CHANGELOG
lib/Twig/Environment.php