Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 327 Vote(s) - 3.5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Small PHP error Too few arguments to function on php72

#1
I need help fixing a small problem with my php script to work on php7.2, the code below works on php7.0 but doesn't work on php7.1 or 7.2 :(

Error showing on debug:

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}

My original code on line 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;
}

---

On template .tpl

<img src="{gravatar email="{if $reply.name eq 'Admin 1'}[email protected]{elseif $reply.name eq 'Admin 2'}[email protected]{elseif $reply.name eq 'Admin 3'}[email protected]{elseif $reply.name eq 'Admin 4'}[email protected]{/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">
Reply

#2
Missing arguments would only trigger a warning until PHP/7.0 but since PHP/7.1 they throw a fatal error ([demo][1]). From [7.0 migration guide][2]:

> Previously, a warning would be emitted for invoking user-defined functions with too few arguments. Now, this warning has been promoted to an Error exception. This change only applies to user-defined functions, not internal functions.

Chances are that it never really worked but you've configured PHP to hide error information—something that's no longer useful with fatal errors because they abort execution anyway.

Since you never use the function's second argument, just get rid of it entirely.


[1]:

[To see links please register here]

[2]:

[To see links please register here]

Reply

#3
see [kevinpapst.de][2] (in German); it's from 2008 and so is the syntax ...

meanwhile the [documentation][1] says something else about "Writing Plugins":

>As a general rule, the currently evaluated template's `Smarty_Internal_Template` object is always passed to the plugins as the last parameter with two exceptions:

- modifiers do not get passed the `Smarty_Internal_Template` object at all.

- blocks get passed $repeat after the `Smarty_Internal_Template` object to keep backwards compatibility to older versions of Smarty.

for example:

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

to be used alike:

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

<img src="{$gravatarURL}" height="60" width="60">

[1]:

[To see links please register here]

[2]:

[To see links please register here]

Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through