1.2.434. Exit() Usage¶
Try exiting the function/class with return, or throw exception that may be caught later in the code.
<?php
// Throw an exception, that may be caught somewhere
throw new Exception('error');
// Dying with error message.
die('error');
function foo() {
//exiting the function but not dying
if (somethingWrong()) {
return true;
}
}
?>
1.2.434.1. Suggestions¶
Avoid exit and die. Let the script finish.
Throw an exception and let it be handled before finishing
1.2.434.2. Specs¶
Short name |
Structures/ExitUsage |
Rulesets |
|
Exakat since |
0.8.4 |
PHP Version |
All |
Severity |
Major |
Time To Fix |
Quick (30 mins) |
Precision |
Very high |
Features |
exit |
ClearPHP |
|
Examples |
|
Available in |