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 !=
.
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 assame as()
in Twig.