Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/278.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
小PHP错误:参数太少,无法在php72上运行_Php_Smarty_Php 7.1_Whmcs_Php 7.2 - Fatal编程技术网

小PHP错误:参数太少,无法在php72上运行

小PHP错误:参数太少,无法在php72上运行,php,smarty,php-7.1,whmcs,php-7.2,Php,Smarty,Php 7.1,Whmcs,Php 7.2,我需要帮助修复php脚本的一个小问题,以便在php7.2上工作,下面的代码在php7.0上工作,但在php7.1或7.2上不工作:( 调试时显示错误: ArgumentCountError: Too few arguments to function smarty_function_gravatar(), 1 passed and exactly 2 expected in public_html/includes/hooks/custom-function.php: Line 91

我需要帮助修复php脚本的一个小问题,以便在php7.2上工作,下面的代码在php7.0上工作,但在php7.1或7.2上不工作:(

调试时显示错误:

    ArgumentCountError: Too few arguments to function smarty_function_gravatar(), 1 passed and exactly 2 expected in public_html/includes/hooks/custom-function.php: Line 91


Stack trace:
    #0 /public_html/includes/hookfunctions.php(0): smarty_function_gravatar(Array)
    #1 /public_html/includes/clientareafunctions.php(0): run_hook('ClientAreaPage', Array)
    #2 /public_html/login.php(0): outputClientArea('login', false, Array)
    #3 /public_html/member/viewticket.php(0): unknown()
    #4 {main}
我在第91行的原始代码:

 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;
 }

关于template.tpl

<img src="{gravatar email="{if $reply.name eq 'Admin 1'}admin1@domain.com{elseif $reply.name eq 'Admin 2'}admin2@domain.com{elseif $reply.name eq 'Admin 3'}admin3@domain.com{elseif $reply.name eq 'Admin 4'}admin4@domain.com{/if}" size="140"}" height="60" width="60">

{elseif $reply.contactid} <img src="{gravatar email="$replyemail" size="140"}" height="60" width="60">

{elseif $reply.userid} 
<img src="{gravatar email="$replyemail" size="140" default="/default-avatar.png"}" height="60" width="60">
{else} 
<img src="{gravatar email="$replyemail" size="140" default="/default-avatar.png"}" height="60" width="60">

{elseif$reply.contactid}
{elseif$reply.userid}
{else}
请参阅(德语);这是2008年的版本,语法也是如此

与此同时,该报告还提到了关于“编写插件”的其他内容:

一般来说,当前评估的模板的
Smarty\u Internal\u template
对象始终作为最后一个参数传递给插件,但有两个例外:

  • 修改器根本不会通过
    Smarty\u Internal\u模板
    对象

  • 块在
    Smarty\u Internal\u Template
    对象之后通过$repeat,以保持与旧版本Smarty的向后兼容性

例如:

function smarty_function_gravatar(array $params, Smarty_Internal_Template $template) {

    $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'])) {
        $template->smarty->assign($params['assign'], $url);
        return;
    }
    return $url;
}
类似地使用:

{gravatar email="example@example.com" size="60" rating="X" assign="gravatarURL" default="http://www.example.com/default_gravatar.jpg"}

<img src="{$gravatarURL}" height="60" width="60">
{gravatar电子邮件=”example@example.com“size=“60”rating=“X”assign=“gravatarURL”默认值=”http://www.example.com/default_gravatar.jpg"}

在PHP/7.0之前,缺少参数只会触发警告,但在PHP/7.1之后,它们会抛出致命错误()。来自:

以前,调用参数太少的用户定义函数会发出警告。现在,此警告已升级为错误异常。此更改仅适用于用户定义函数,而不适用于内部函数

很有可能它从未真正起作用,但您已经将PHP配置为隐藏错误信息,这对于致命错误不再有用,因为它们无论如何都会中止执行


由于您从不使用函数的第二个参数,只需将其完全去掉。

您要将多少个参数传递给
smarty\u function\u gravatar()
?该消息建议为0或1而不是2。
1已通过,预期正好为2。
1…我认为错误非常清楚。@ggdx我已更新了“抱歉,我不太明白”的后可能副本,无论您建议删除代码还是添加代码,请检查Martin的答案。我认为这不是自定义函数不过是一个为旧版本设计的小树枝插件。