title: Two sequential heredocs in PHP?
body: <p>What's wrong with the following code:</p>
  
  <pre><code>static function queryVariables($variable_name)
      {
  
          $query = &lt;&lt;&lt;SQL
  SELECT * 
    FROM variables v 
      WHERE v.nam = '$variable_name'
  SQL;    
  
      $ans = self::$conn-&gt;select($query);
  
  
        $query = &lt;&lt;&lt;SQL
  SELECT v.id, v.nam variable_nam, v.descr variable_descr, us.id subset_id, us.unit_id, us.ord, us.nam subset_nam, us.color, us.min_value, us.max_value 
    FROM variables v 
      LEFT JOIN unit_subsets us ON v.unit_id = us.unit_id
      WHERE v.nam = '$variable_name'
  SQL;
  
          $ans = self::$conn-&gt;select($query);
  
          return $ans;
      }
  </code></pre>
  
  <p>I know it is logically incorrect, because overwrites <code>$query</code> variable. But the question is: why it doesn't understand there are two heredocs here? It treats entire block as one heredoc and throws</p>
  
  <pre><code>Undefined variable: ans
  </code></pre>
  
  <p>exception because it tries to embed <code>$ans</code> into heredoc.</p>
  
  <p>How to fix?</p>