title: In PHP, how do I substitute a string variable before it's evaluated?
body: <p>Is it possible to expand/substitute a variable before PHP tries to evaluate its truth value?</p>
  
  <p>I'm trying to code a single Wordpress template that will execute different queries depending on which page we're on. If we're on the homepage, the query should look like this:</p>
  
  <pre><code>while ( $postlist-&gt;have_posts() ) : $postlist-&gt;the_post();
      // code...
  </code></pre>
  
  <p>If we're not on the homepage, the query should look like this:</p>
  
  <pre><code>while ( have_posts() ): the_post();
      // code...
  </code></pre>
  
  <p>So I thought I would try this:</p>
  
  <pre><code>$query_prefix = ( is_front_page() ) ? '$postlist-&gt;' : '';
  
  $query_condition = $query_prefix.'have_posts()';
  $query_do        = $query_prefix.'the_post()';
  
  while ( $query_condition ): $query_do;
      // code...
  </code></pre>
  
  <p>The problem is, this is creating an infinite loop, because <code>$query_condition</code> is a string and evaluates to TRUE. It seems like PHP never 'reads' the content of the variable. I need my variable to expand itself literally, and only then offer itself for evaluation. Can anyone please tell me how how to do this?</p>