title: Check if the variable passed as an argument is set
body: <p>I want to check if a variable called $smth is blank (I mean empty space), and I also want to check if it is set using the function I defined below:</p>
  
  <pre><code>function is_blank($var){
      $var = trim($var);
      if( $var == '' ){
          return true;
      } else {
          return false;
      }
  }
  </code></pre>
  
  <p>The problem is I can't find a way to check if variable <code>$smth</code> is set inside <code>is_blank()</code> function. The following code solves my problem but uses two functions:</p>
  
  <pre><code>if( !isset($smth) || is_blank($smth) ){
      // code;
  }
  </code></pre>
  
  <p>If I use an undeclared variable as an argument for a function it says:</p>
  
  <pre><code>if( is_blank($smth) ){
      //code;
  }
  
  Undefined variable: smth in D:\Www\www\project\code.php on line 41
  </code></pre>
  
  <p>Do you have a solution for this?</p>
  
  <h3>Solution</h3>
  
  <p>This is what I came up with:</p>
  
  <pre><code>function is_blank(&amp;$var){ 
      if( !isset($var) ){ 
          return true; 
      } else { 
          if( is_string($var) &amp;&amp; trim($var) == '' ){ 
              return true; 
          } else { 
              return false; 
          } 
      } 
  }
  </code></pre>
  
  <p>and works like a charm.  Thank you very much for the <a href="https://stackoverflow.com/a/3547060/15168">idea</a>, <a href="https://stackoverflow.com/users/385378/nikic">NikiC</a>.</p>