Twig: Support ===

Created on 11 Jan 2017  路  10Comments  路  Source: twigphp/Twig

I just wrote some twig template which contained === and the parser failed:

Twig_Error_Syntax: Unexpected token "operator" of value "=" in "foo.html.twig" at line 19. in Twig_ExpressionParser->parsePrimaryExpression() (line 208 of vendor/twig/twig/lib/Twig/ExpressionParser.php).

I wonder whether twig should simply treat === as == or even provide some form of strict comparison.

Most helpful comment

One thing which could be done is to not support "===" but instead throw a helpful exception telling people about "same as"

All 10 comments

=== does exist in Twig, but the name of the test is same as.

Right, I'm simply wondering whether === should be treated as "same as" automatically. I'm wondering whether its just me who is so stupid falling into that trap :)

This is really not like a feature request or so, I'm really just wondering

That's a good question and one for which we had a discussion in the past. The conclusion was that === is confusing for anyone not familiar with PHP. So, we decided to support it via same as instead.

One thing which could be done is to not support "===" but instead throw a helpful exception telling people about "same as"

That makes sense. Anyone willing to submit a PR for that? Could be done in the 1.x branch.

Absolutely

:+1: for closing PRs.

@dawehner It's not closed but merged ;)

Oh haha. Well even better :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

xxfaxy picture xxfaxy  路  6Comments

rungta picture rungta  路  3Comments

CriseX picture CriseX  路  4Comments

ericmorand picture ericmorand  路  4Comments

reatang picture reatang  路  4Comments