php - 从废弃的函数 create_function 迁移
问题描述
我的脚本中有函数,但是在将我的 php 版本更新到 7.3 后,我收到一个通知,函数 create_function 已被弃用。我该如何迁移,我可以使用什么来代替 create_function?
function rc4($key, $data){
// Store the vectors "S" has calculated
static $SC;
// Function to swaps values of the vector "S"
$swap = create_function('&$v1, &$v2', '
$v1 = $v1 ^ $v2;
$v2 = $v1 ^ $v2;
$v1 = $v1 ^ $v2;
');
$ikey = crc32($key);
if (!isset($SC[$ikey])) {
// Make the vector "S", basead in the key
$S = range(0, 255);
$j = 0;
$n = strlen($key);
for ($i = 0; $i < 255; $i++) {
$char = ord($key{$i % $n});
$j = ($j + $S[$i] + $char) % 256;
$swap($S[$i], $S[$j]);
}
$SC[$ikey] = $S;
} else {
$S = $SC[$ikey];
}
// Crypt/decrypt the data
$n = strlen($data);
$data = str_split($data, 1);
$i = $j = 0;
for ($m = 0; $m < $n; $m++) {
$i = ($i + 1) % 256;
$j = ($j + $S[$i]) % 256;
$swap($S[$i], $S[$j]);
$char = ord($data[$m]);
$char = $S[($S[$i] + $S[$j]) % 256] ^ $char;
$data[$m] = chr($char);
}
return $data; implode('', $data);
}
enter code here
解决方案
推荐阅读
- c - 在 C 语言中应该如何处理警告?
- c# - EmguCV 将特定值设置为 Mat C#
- javascript - 图像未添加到场景中 -Phaser 3.5
- sql-server - SQL Server 查询结果以 GB 为单位
- xamarin - OSX 上的 Xamarin 访问 Web 服务
- ios - SwiftUI:在同一行上组合文本
- filter - 如何在 Prolog 中过滤具有多个条件的列表?
- python-3.x - MongoDB + Python,意外的数字类型
- angular - 使用 Fetch 发送 FormData
- azure - 使用多个电子邮件接收器/Set-AzActionGroup 更新操作组