Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The ' ** ' operator does not work on negative numbers as an expected way . #2891

Closed
unique1984 opened this issue Mar 12, 2019 · 4 comments
Closed

Comments

@unique1984
Copy link

unique1984 commented Mar 12, 2019

PHP Version : PHP 7.3.3-1+020190307202245.32+stretch1.gbp32ebb2
(Php versions 7.1 and 7.2 I tested it, and behavior is the same.)

Symfony Version : 4.2
Twig Version : symfony/twig-bundle": "4.2.3
Lsb Release : Debian GNU/Linux 9.8 (stretch)


in raw php code (as expected):
-2 ** 2 = 4

image


in twig (something is wrong in here);
{{ -2 ** 2 }}
{{ -2 ** 3 }}
...

image

@stof
Copy link
Member

stof commented Mar 12, 2019

I think this might be related to some precedence issue in the way this is parsed. It may be parsed as - (2 ** 2) here instead of (-2) ** 2 (and so using a variable to store the -2 or using braces may not be affected)

@stof
Copy link
Member

stof commented Mar 12, 2019

btw, in PHP, if you remove the usage of a variable but inline the number (making it equivalent to the Twig code), you get the same behavior than the one you report in Twig.

@unique1984
Copy link
Author

I get it, in parenthesis it didn't work but defining a negative number variable works.
Thank you @stof , have a nice day.


This way works!

image

image

@stof
Copy link
Member

stof commented Mar 12, 2019

yeah, parenthesis may not work, because Twig would parse it as expected, but compile it to PHP without braces, and so be affected at the PHP level.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants