My PHP code not working with PHP 7.1 or 7.2

心已入冬 提交于 2019-12-11 18:34:23

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!