NemoPS
NemoPS

Reputation: 411

Function accepting only 2 over 6 parameters. Func_num_args returns 2

I'm having a weird issue. Basically I have a function, which is called by the smarty template engine, and should accept 6 parameters. Actually the problem is, that it is only accepting 2!

And even more weird, calling func_num_args() inside that function gived me too... but have a look a it

function smarty_modifier_truncate($string, $length = 80, $etc = '...', $break_words = false, $middle = false, $charset = 'UTF-8')
{
var_dump($break_words);
var_dump(func_num_args());

if (!$length)
    return '';

if (Tools::strlen($string) > $length)
{
    $length -= min($length, Tools::strlen($etc));
    if (!$break_words && !$middle)
        $string = preg_replace('/\s+?(\S+)?$/u', '', Tools::substr($string, 0, $length+1, $charset));
    return !$middle ? Tools::substr($string, 0, $length, $charset).$etc : Tools::substr($string, 0, $length/2, $charset).$etc.Tools::substr($string, -$length/2, $length, $charset);
}
else
    return $string;
}

Those other parameters are set, since "break words" is being outputted, and if i change them ,the effects is noticeble. Really weird. is there any solution?

PHP version 5.4.3 running on local wamp

Upvotes: 0

Views: 92

Answers (1)

KingCrunch
KingCrunch

Reputation: 131931

func_num_args() returns the number of arguments, that are actually passed to the function when calling, not the number of accepted arguments. That wouldn't eve be possible, because PHP always accepts an arbitrary number of arguments

function foo () {
  var_dump(func_num_args());
  var_dump(func_get_args());
}
foo(1, 'a', null, true);

http://codepad.org/nhqgb5kK

Upvotes: 2

Related Questions