note 97252 added to function.exit

From: Date: Sat, 10 Apr 2010 14:41:33 +0000
Subject: note 97252 added to function.exit
Groups: php.notes 
Request: Send a blank email to php-notes+get-168103@lists.php.net to get a copy of this message
A curious note on the use of exit in PHP While working on three different servers simultaneously I have noted an oddity coming from a regular application dev background. Excuse the pseudo examples <?php myfunction(){ $res=0; foreach{$testArray As $key => $value){ $res = $value; if($res==1){exit(1);} } return $res; } ?> Aught to be equivalent in it's execution to... <?php myfunction(){ $res=0; foreach{$testArray As $key => $value){ if($value==1){return $value;} } //if you get here you didn't find the res value other than 0 return $res; } ?> Aught to be equivalent in it's execution to... (This is the ONLY option that works as intended in all my tests which means massive needless looping.) <?php myfunction(){ $res=0; foreach{$testArray As $key => $value){ if($value==1){res = $value;} } //loop on until you get here return $res; } ?> ...however it is NOT. In two out of three servers the use of Exit() acts as a Super Global and kills the whole site. On some occasions the exit will have no effect at all and in others still... well hmmm needless to say, this seems like randomized behavior somehow. I didn't see any difference between PHP 5.2.6 and PHP 5.2.8 in this. ---- Server IP: 69.147.83.197 Probable Submitter: 212.181.164.190 ---- Manual Page -- http://www.php.net/manual/en/function.exit.php Edit -- https://master.php.net/note/edit/97252 Del: integrated -- https://master.php.net/note/delete/97252/integrated Del: useless -- https://master.php.net/note/delete/97252/useless Del: bad code -- https://master.php.net/note/delete/97252/bad+code Del: spam -- https://master.php.net/note/delete/97252/spam Del: non-english -- https://master.php.net/note/delete/97252/non-english Del: in docs -- https://master.php.net/note/delete/97252/in+docs Del: other reasons-- https://master.php.net/note/delete/97252 Reject -- https://master.php.net/note/reject/97252 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#168103) next »