summaryrefslogtreecommitdiff
path: root/it.class
diff options
context:
space:
mode:
authorChristian Schneider2026-04-09 16:45:03 +0200
committerChristian Schneider2026-04-09 16:45:03 +0200
commit182998553e8b012205699e4c4b8ccb7ad1903777 (patch)
tree68e5c5d1d1a323fa7c7b61c8d17e708780ab4a07 /it.class
parentceeda2d908874d51fb59c3cadbf067f75f405116 (diff)
downloaditools-182998553e8b012205699e4c4b8ccb7ad1903777.tar.gz
itools-182998553e8b012205699e4c4b8ccb7ad1903777.tar.bz2
itools-182998553e8b012205699e4c4b8ccb7ad1903777.zip
Simplify creation of helper function and avoid eval in callable string case
Diffstat (limited to 'it.class')
-rw-r--r--it.class8
1 files changed, 3 insertions, 5 deletions
diff --git a/it.class b/it.class
index ddb95eb..d5d98dd 100644
--- a/it.class
+++ b/it.class
@@ -1113,11 +1113,9 @@ static function date($format = "", $stamp = null)
# Internal: Convert expression or funcname or function literal to callable
static function createfunc($code)
{
- if ($code instanceof Closure && (new ReflectionFunction($code))->getNumberOfRequiredParameters() == 1)
- $code = function($dummy, $v) use ($code) {return $code($v);};
-
- if (is_string($code) && it::match('^[\w:]+$', $code) && is_callable($code))
- $code .= '($v)';
+ if ($code instanceof Closure && (new ReflectionFunction($code))->getNumberOfRequiredParameters() == 1 ||
+ is_string($code) && it::match('^[\w:]+$', $code) && is_callable($code))
+ $code = static fn($dummy, $v) => $code($v);
if (!is_callable($func = $code) && !function_exists($func = "_it_map_" . md5($code)))
eval("function $func(\$k, \$v) { return $code; }"); # Anonymous functions/closures are slower than this (PHP 7.1)