1.2.437. Exit() Usage¶
Using exit or die() in the code makes the code untestable (it will break unit tests). Moreover, if there is no reason or string to display, it may take a long time to spot where the application is stuck. 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.437.1. Connex PHP features¶
1.2.437.1.1. Suggestions¶
Avoid exit and die. Let the script finish.
Throw an exception and let it be handled before finishing
1.2.437.1.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 |
ClearPHP |
|
Examples |
|
Available in |