note 116709 deleted from function.return by peehaa

From: Date: Sun, 28 Apr 2019 10:28:43 +0000
Subject: note 116709 deleted from function.return by peehaa
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-210789@lists.php.net to get a copy of this message
Note Submitter: Russell Weed ---- 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); ?>

« previous php.notes (#210789) next »