title: Check if variable is set and then echo it without repeating?
body: <p>Is there a concise way to check if a variable is set, and then echo it without repeating the same variable name?</p>
  
  <p>Instead of this:</p>
  
  <pre><code>&lt;?php
      if(!empty($this-&gt;variable)) {
          echo '&lt;a href="', $this-&gt;variable, '"&gt;Link&lt;/a&gt;';
      }
  ?&gt;
  </code></pre>
  
  <p>I'm thinking about something in the lines of this C-style pseudocode:</p>
  
  <pre><code>&lt;?php
      echo if(!empty($this-&gt;variable, '&lt;a href="', %s, '"&gt;Link&lt;/a&gt;'));
  ?&gt;
  </code></pre>
  
  <p>PHP has <a href="http://www.php.net/manual/en/function.sprintf.php">sprintf</a>, but it doesn't quite do what I was hoping for. If course I could make a method/function out of it, but surely there must be a way to do it "natively"?</p>
  
  <p>Update:
  Ternary operations would also repeat the <code>$this-&gt;variable</code> part, if I understood it?</p>
  
  <pre><code>echo (!empty($this-&gt;variable) ? '&lt;a href="',$this-&gt;variable,'"&gt;Link&lt;/a&gt; : "nothing");
  </code></pre>