1.2.1188. Throw Functioncall¶
When the new
keyword is forgotten, then the class constructor is used as a function name, and now exception is emitted, but an Undefined function
fatal error is emitted.
<?php
// Forgotten new
throw \RuntimeException('error!');
// Code is OK, function returns an exception
throw getException(ERROR_TYPE, 'error!');
function getException(ERROR_TYPE, $message) {
return new \RuntimeException($messsage);
}
?>
1.2.1188.1. Suggestions¶
Add the new operator to the call
Make sure the function is really a functioncall, not a class name
Use return type for functions, so that Exception may be detected
1.2.1188.2. Specs¶
Short name |
Exceptions/ThrowFunctioncall |
Rulesets |
|
Exakat since |
0.8.4 |
PHP Version |
All |
Severity |
Major |
Time To Fix |
Instant (5 mins) |
Precision |
Medium |
Features |
exception |
Examples |
|
Available in |