title: The 'return' keyword is not working correctly in PHP
body: <p>I am using this piece of function to check if a file exists. If the file exists then I am changing its name:</p>
  <pre><code>function checkFileExist($fileName, $z, $ext, $folderWIthFileName){
      $tmpNam = &quot;&quot;;
      if (file_exists($fileName . &quot;_&quot; . $z . &quot;.&quot; . $ext)) {
          $z = $z + 1;
          checkFileExist($fileName, $z, $ext, $folderWIthFileName);
      }
      else {
          $tmpNam = $fileName . &quot;_&quot; . $z;
          echo &quot;in else &lt;br&gt; &quot; . $fileName . &quot;_&quot; . $z . &quot;&lt;br&gt;&quot;;
      }
      return $tmpNam;
  }
  </code></pre>
  <p>And calling this function like</p>
  <pre><code>$definename = checkFileExist($folderWIthFileName . &quot;/&quot; . $InvId, $z, $ext, $folderWIthFileName);
  echo &quot;new name is &quot; . $definename;
  </code></pre>
  <p>But this gives me output like this:</p>
  <pre class="lang-none prettyprint-override"><code>in else
  444_2015-10-27/444_3
  new name is
  </code></pre>
  <p>You can see return is not working correctly. What am I doing wrong here?</p>