18
votes
Accepted
What's the difference between using single and double quotes in strings?
There is a small difference, single-quoted strings don't support interpolation:
{% set string = 'There is a #{car}.' %}
The above example won't work. If you want to use it, you need to wrap your ...
14
votes
Accepted
When to use " is same as" and when to use "=="
Looking at the Twig code, they have this documented for the “same as” test:
Checks if a variable is the same as another one (=== in PHP).
I won’t re-hash the details of === vs. == in PHP because ...
7
votes
Accepted
Difference between using subscript syntax and "dot" syntax when accessing attributes of a variable or advantages of usage one of them
They're both the same for the most part.
The only time I'd use the second way you listed is when the property is a variable.
For instance:
{% set foo = 'name' %}
{{ variable[foo] }}
This will give ...
4
votes
Difference between using subscript syntax and "dot" syntax when accessing attributes of a variable or advantages of usage one of them
Generally speaking, no. They are just two ways of saying the same thing.
Dot syntax is necessary when you are referring to a method within an object. However, if you are only trying to access the ...
1
vote
When to use " is same as" and when to use "=="
For example:
false == 0 will be true
false === 0 will be false
It is very useful when you use such functions as file_put_contents() and preg_match().
The first function returns a number of bytes ...
Only top scored, non community-wiki answers of a minimum length are eligible