【发布时间】:2019-09-14 13:36:00
【问题描述】:
我在 php.ini 中定义了特征。我试图在两个具有相同特征的函数之间进行通信,但我遇到了致命错误。
---------------错误------- ------------- 致命错误:调用未定义函数 crypto_rand_secure() 在 /var/www/html/clients/assuredo/include/config/generateToken/token.php 第 28 行
我试图在函数getToken() 中调用函数crypto_rand_secure()。
trait token
{
public function crypto_rand_secure($min, $max)
{
$range = $max - $min;
if ($range < 1) return $min; // not so random...
$log = ceil(log($range, 2));
$bytes = (int) ($log / 8) + 1; // length in bytes
$bits = (int) $log + 1; // length in bits
$filter = (int) (1 << $bits) - 1; // set all lower bits to 1
do {
$rnd = hexdec(bin2hex(openssl_random_pseudo_bytes($bytes)));
$rnd = $rnd & $filter; // discard irrelevant bits
} while ($rnd > $range);
return $min + $rnd;
}
public function getToken($length)
{
$token = "";
$codeAlphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
$codeAlphabet.= "abcdefghijklmnopqrstuvwxyz";
$codeAlphabet.= "0123456789";
$max = strlen($codeAlphabet); // edited
for ($i=0; $i < $length; $i++) {
$token .= $codeAlphabet[crypto_rand_secure(0, $max-1)];
}
return $token;
}
}
【问题讨论】:
-
请不要使用不必要的标签——整个问题与“函数式编程”无关,毕竟标签
call不应该使用
标签: php function functional-programming call traits