Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

E_USER_WARNING: math: function call a not allowed

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Bugs
View previous topic :: View next topic  
Author Message
Mastershrimp
Smarty Regular


Joined: 21 Dec 2009
Posts: 53

PostPosted: Tue Feb 14, 2012 11:30 am    Post subject: E_USER_WARNING: math: function call a not allowed Reply with quote

Hi!

Since a few days I observed a new E_USER_WARNING that I havent seen before:
Code:
math: function call a not allowed


The only thing I changed in the past days was an update from 3.1.7 to the latest version of the trunk (because of another issue), but I'm not sure if that has anything to do with the problem.

The template code is:
Code:
{math equation="round((a/b)*100,0)" a=$ans.wert b=$maxwert}

And the {math}-call is within a {foreach}.

Any ideas? Bug? Admittedly I havent spent much time debugging it, since it sort of happened out of the blue (without me changing anything in particular).

Btw: "Who" says that the call is not allowed? PHP or smarty?

Best regards
Ms
Back to top
View user's profile Send private message
rodneyrehm
Administrator


Joined: 30 Mar 2007
Posts: 674
Location: Germany, border to Switzerland

PostPosted: Tue Feb 14, 2012 12:27 pm    Post subject: Reply with quote

plugins/function.math.php triggers said error on line 50.
Since »E_USER_WARNING: math: function call a not allowed« is missing the function name, I quess the regex in line 46 fails somehow.

please run the following code in your PHP environment and check if the result you get is the same I provided. If it's not, your PCRE lib is out of date.

Code:
$equation = "round((a/b)*100,0)";
preg_match_all("!(?:0x[a-fA-F0-9]+)|([a-zA-Z][a-zA-Z0-9_]*)!",$equation, $match);
var_dump($match[1]);
result:
Code:
array
  0 => string 'round' (length=5)
  1 => string 'a' (length=1)
  2 => string 'b' (length=1)

_________________
Twitter
Back to top
View user's profile Send private message Visit poster's website
rodneyrehm
Administrator


Joined: 30 Mar 2007
Posts: 674
Location: Germany, border to Switzerland

PostPosted: Tue Feb 14, 2012 12:51 pm    Post subject: Reply with quote

And since you're already using Smarty 3.x you might consider dropping the (slow) {math} function in favor of vanilla equations:
Code:
{$a = 100}
{$b = 200}
{$c = round(($a / $b) * 100, 0)}
{$c}


It's a simpler syntax and quite a bit faster than the old {math} plugin.
_________________
Twitter
Back to top
View user's profile Send private message Visit poster's website
Mastershrimp
Smarty Regular


Joined: 21 Dec 2009
Posts: 53

PostPosted: Tue Feb 14, 2012 1:39 pm    Post subject: Reply with quote

Thanks! I'll look into that and get back to you asap.
Back to top
View user's profile Send private message
Mastershrimp
Smarty Regular


Joined: 21 Dec 2009
Posts: 53

PostPosted: Tue Feb 14, 2012 1:57 pm    Post subject: Reply with quote

According to one of my coworkers the result is:
Code:
array(3) { [0]=> string(5) "round" [1]=> string(1) "a" [2]=> string(1) "b" }


Seems to be ok I guess.

We will try the vanilla equations though. Thanks!
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Bugs All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP