Answers.Body: <p>For example:</p>
  <p><code>false == 0</code> will be <code>true</code></p>
  <p><code>false === 0</code> will be <code>false</code></p>
  <p>It is very useful when you use such functions as <code>file_put_contents()</code> and <code>preg_match()</code>.</p>
  <p>The first function returns a number of bytes writtent to the file (which can be 0 if nothing was written what does not mean that it's false). And the second one returns 1 if something was found otherwise 0.</p>
  <p>They always warn people when you must check for the variable type too. <a href="https://www.php.net/manual/en/function.preg-match.php" rel="nofollow noreferrer">Php.net</a>: Go at &quot;Return values&quot; and you will see a red Warning block.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-06-18T08:28:00.463Z
Answers.LastActivityDate: 2014-06-18T08:28:00.463Z
Answers.LastEditDate: 2023-11-17T19:42:58.570Z
Answers.UserDisplayName: AlexTorscho
Answers.Body: <p>Looking at the Twig code, they have this documented for the “same as” test:</p>
  
  <blockquote>
    <p>Checks if a variable is the same as another one (=== in PHP).</p>
  </blockquote>
  
  <p>I won’t re-hash the details of === vs. == in PHP because there is an excellent comparison here: <a href="https://stackoverflow.com/questions/80646/how-do-the-php-equality-double-equals-and-identity-triple-equals-comp">https://stackoverflow.com/questions/80646/how-do-the-php-equality-double-equals-and-identity-triple-equals-comp</a></p>
  
  <p>The money quote is:</p>
  
  <blockquote>
    <p>== compares the values of variables for equality, type casting as necessary. === checks if the two variables are of the same type AND have the same value.</p>
  </blockquote>
  
  <p>And here’s what the PHP docs have to say:</p>
  
  <p><a href="http://www.php.net/manual/en/language.operators.comparison.php">http://www.php.net/manual/en/language.operators.comparison.php</a></p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-06-15T15:10:48.373Z
Answers.LastActivityDate: 2014-06-15T19:35:05.367Z
Answers.LastEditDate: 2014-06-15T19:35:05.367Z
Answers.UserDisplayName: Brad Bell
Body: <pre><code>{% if foo is same as('bar') %}
  </code></pre>
  
  <p>vs.</p>
  
  <pre><code>{% if foo == 'bar' %}
  </code></pre>
  
  <p>When to use first and when to use second? Does one of them has advantages over another?</p>
  
Tags: <templating><difference>
Title: When to use " is same as" and when to use "=="
ThreadText: # When to use " is same as" and when to use "=="
  
  (Asked by: username_0 on 2014-06-15)
  
  ```
  {% if foo is same as('bar') %}
  
  ```
  
  vs.
  
  ```
  {% if foo == 'bar' %}
  
  ```
  
  When to use first and when to use second? Does one of them has advantages over another?
  
  **Tags:** templating, difference
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_2 on 2014-06-15. Score: 14 | Accepted answer
  
  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 there is an excellent comparison here: <https://stackoverflow.com/questions/80646/how-do-the-php-equality-double-equals-and-identity-triple-equals-comp>
  
  The money quote is:
  
  > == compares the values of variables for equality, type casting as necessary. === checks if the two variables are of the same type AND have the same value.
  
  And here’s what the PHP docs have to say:
  
  <http://www.php.net/manual/en/language.operators.comparison.php>
  
  
  ---
  
  ### Answer by username_1 on 2014-06-18. Score: 1
  
  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 writtent to the file (which can be 0 if nothing was written what does not mean that it's false). And the second one returns 1 if something was found otherwise 0.
  
  They always warn people when you must check for the variable type too. [Php.net](https://www.php.net/manual/en/function.preg-match.php): Go at "Return values" and you will see a red Warning block.
  
  
  ---
  
  