note 116709 added to function.return
| From: | RussellWeed | Date: | Fri, 13 Feb 2015 16:09:36 +0000 |
| Subject: | note 116709 added to function.return | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-201729@lists.php.net to get a copy of this message | ||
Following up on Tom and warhog's comments regarding using return in global scope, here is
another reason not to do it:
For command line scripts, the return statement will NOT return a status to the OS!
<?php
if ($somethingBad)
return 42; // This will not work! You'll get 0 back instead!
else
return 0;
?>
Instead, you must use exit(): http://php.net/exit
<?php
if ($somethingBad)
exit(42); // OS will receive (int) 42 as the return code
else // everything is fine
exit(0);
?>
----
Server IP: 72.52.91.14
Probable Submitter: 66.210.181.98
----
Manual Page -- http://php.net/manual/en/function.return.php
Edit -- https://master.php.net/note/edit/116709
Del: integrated -- https://master.php.net/note/delete/116709/integrated
Del: useless -- https://master.php.net/note/delete/116709/useless
Del: bad code -- https://master.php.net/note/delete/116709/bad+code
Del: spam -- https://master.php.net/note/delete/116709/spam
Del: non-english -- https://master.php.net/note/delete/116709/non-english
Del: in docs -- https://master.php.net/note/delete/116709/in+docs
Del: other reasons-- https://master.php.net/note/delete/116709
Reject -- https://master.php.net/note/reject/116709
Search -- https://master.php.net/manage/user-notes.php