问题
I have small issue with php coding for newest php version, the original code:
<?php
function smarty_function_gravatar($params, &$smarty) {
$email = (isset($params['email']) ? trim(strtolower($params['email'])) : '');
$rating = (isset($params['rating']) ? $params['rating'] : 'R');
$url = "https://www.gravatar.com/avatar/".md5($email) . "?r=".$rating;
if(isset($params['default']))
$url .= "&d=".urlencode($params['default']);
if(isset($params['size']))
$url .= "&s=".$params['size'];
if(isset($params['assign'])) {
$smarty->assign($params['assign'], $url);
return;
}
return $url;
}
add_hook('ClientAreaPage', 1, 'smarty_function_gravatar');
From error logs:
{main} {"exception":"[object] (ArgumentCountError(code: 0): Too few arguments to function smarty_function_gravatar(), 1 passed and exactly 2 expected at /home/myuser/public_html/includes/hooks/avatar.php:3)"} []
Please help to replace new code for php 7.2
回答1:
I can only suggest the following, I have never used whmcs before, but its possible that the global $smarty;
variable can been referenced instead.
change
function smarty_function_gravatar($params, &$smarty) {
to
function smarty_function_gravatar($params){
global $smarty;
来源:https://stackoverflow.com/questions/49642149/my-php-code-not-working-with-php-7-1-or-7-2