title: PHP Shorthand If/Else when using return
body: <p>There are few nice ways to write shorthands in PHP.</p>
  
  <h3>Less common but shortest example:</h3>
  
  <pre><code>!isset( $search_order ) &amp;&amp; $search_order = 'ASC';
  </code></pre>
  
  <h3>More common but a little longer:</h3>
  
  <pre><code>!isset( $search_order ) ? $search_order = 'ASC' : $search_order = NULL;
  </code></pre>
  
  <h3>We can even combine examples above in to an amazing shorthand:</h3>
  
  <pre><code>!isset( $_POST['unique_id'] ) &amp;&amp; preg_match( '/^[a-zA-Z0-9]{8}$/', $_POST['unique_id'] ) ? $post_unique_id = $_POST['unique_id'] : $post_unique_id = NULL;
  </code></pre>
  
  <p><br>
  But how do we use examples above with functions and return, example:</p>
  
  <pre><code>function filter_gender_request($data) {  
      preg_match('/(fe)?male/i', $data, $data);
      isset($data[0]) &amp;&amp; return $data[0]; // It doesn't work here with return
  }
  </code></pre>
  
  <p>At the same time, if I state the following, instead of <code>isset($data[0]) &amp;&amp; return $data[0];</code> then everything works as expected:</p>
  
  <pre><code>if (isset($data[0]) ) {
      return $data[0];
  }
  </code></pre>
  
  <p>What am I doing wrong here? If the very first and shortest example works outside of function flawlessly, why then it doesn't work with return? </p>
  
  <p>Is there a possibility to use shorthands with return?</p>