Skip to content

Commit

Permalink
Optimize helper invocation
Browse files Browse the repository at this point in the history
...and reduce reliance on reflection at the same time, see
xp-framework/rfc#338
  • Loading branch information
thekid committed Feb 27, 2021
1 parent a1f6cae commit 50e6279
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/main/php/com/github/mustache/Context.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,9 @@ protected function helper($ptr, $segment) {
if ($ptr instanceof \Closure) {
return $ptr;
} else if (is_object($ptr)) {
$class= typeof($ptr);
if ($class->hasMethod($segment)) {
$method= $class->getMethod($segment);
return function($in, $ctx, $options) use($ptr, $method) {
return $method->invoke($ptr, [$in, $ctx, $options]);
if (method_exists($ptr, $segment)) {
return function($in, $ctx, $options) use($ptr, $segment) {
return $ptr->{$segment}($in, $ctx, $options);
};
}
return null;
Expand Down

0 comments on commit 50e6279

Please sign in to comment.