Twig same as operator

2.1k views Asked by At

When comparing in PHP, it is advisable to use === instead of == due to intransitive nature and quirks like "5 is not a number" == 5.

By that guideline, does it mean that the same as operator should be used instead of == in Twig?:

{# "Wrong" #}
{% if foo.bar == 3 %}

{# Better #}
{% if foo.bar is same as(3) %}

And likewise for is not same as versus !=.

1

There are 1 answers

0
Adam Elsodaney On BEST ANSWER

It makes sense when treating PHP and Twig as two very different tools. Fabien Potencier's main motive for creating Twig was to provide a tool for Web Designers, not Web Developers. (See his blog post for more insight).

Web developers should know to be more explicit and use === as often as possible. In the realm of web design this is perhaps not as vital, but if needed, that feature is available as same as() in Twig.