Is exit needed after return inside a php function? -


<?php  function testend($x) {     if ( ctype_digit($x) ) {         if ( $x == 24 ) {             return true;             exit;         } else {             return false;                  exit;         }     } else {         echo 'if not digit, you\'ll see me.';         return false;         exit;     } }  $a = '2';  if ( testend($a) ) {     echo 'this digit'; } else {     echo 'no digit found'; } ?> 

is exit needed along return when using them inside php function? in case, if evaluated false, i'd end there , exit.

no it's not needed. when return function code after not execute. if @ did execute, stop dead there , not go calling function either. exit should go

according php manual

if called within function, return statement ends execution of current function, , returns argument value of function call. return end execution of eval() statement or script file.

whereas, exit, according php manual

terminates execution of script.

so if exit executing, stop execution right there

edit

just put small example demonstrate exit does. let's have function , want display return value. try this

<?php  function test($i) {     if($i==5)     {         return "five";     }     else     {         exit;     } }   echo "start<br>"; echo "test(5) response:"; echo test(5);  echo "<br>test(4) response:"; echo test(4);   /*no code below line execute now. wont see following `end` message.  if comment line see end message well. because of use of exit*/   echo "<br>end<br>";   ?> 

Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -