【发布时间】:2018-04-27 08:46:22
【问题描述】:
我在发布问题之前检查了this。
这是使用create_function的代码的一小部分
$lambda_functions[$code_hash] = create_function('$action, &$self, $text', 'if ($action == "encrypt") { '.$encrypt.' } else { '.$decrypt.' }');
试过用这种方法
$lambda_functions[$code_hash] = function ( $action, &$self, $text ) use ( $encrypt, $decrypt ) {
if ($action == "encrypt") {
return $encrypt;
} else {
return $decrypt;
}
};
但不能按预期工作 $encrypt 或 $decrypt 将包含看起来像这样的代码
$encrypt = $init_encryptBlock . '
$ciphertext = "";
$text = $self->_pad($text);
$plaintext_len = strlen($text);
$in = $self->encryptIV;
for ($i = 0; $i < $plaintext_len; $i+= '.$block_size.') {
$in = substr($text, $i, '.$block_size.') ^ $in;
'.$_encryptBlock.'
$ciphertext.= $in;
}
if ($self->continuousBuffer) {
$self->encryptIV = $in;
}
return $ciphertext;
';
create_function 工作正常,但anonymous 函数不知道我哪里出错了?
【问题讨论】:
-
您是否尝试过检查您创建的 lambda 代码返回的值?您正在将字符串分配给 $encrypt 您应该在将其提交给 lambda 函数之前使用 eval 函数,例如 @philipp 说 create_function 正在评估字符串作为 php 函数。
-
@ChristopherPelayo 感谢您的输入,
create_function的输出是�lambda_1我也需要一种不使用eval或create_function的方法,因为小心[这里](@ChristopherPelayo感谢您的输入,create_function的输出是�lambda_1我也需要一种不使用eval或create_function'因为caution 的方法
标签: php anonymous-function php-7.2 create-function