1.2.867. Null On New¶
Until PHP 7, some classes instantiation could yield null, instead of throwing an exception.
After issuing a ‘new’ with those classes, it was important to check if the returned object were null or not. No exception were thrown. This inconsistency has been cleaned in PHP 7 : see See Internal Constructor Behavior
<?php
// Example extracted from the wiki below
$mf = new MessageFormatter('en_US', '{this was made intentionally incorrect}');
if ($mf === null) {
echo 'Surprise!';
}
?>
See also PHP RFC: Constructor behaviour of internal classes.
1.2.867.1. Connex PHP features¶
1.2.867.1.1. Suggestions¶
Remove the check on null after a new instantiation
1.2.867.1.2. Specs¶
Short name |
Classes/NullOnNew |
Rulesets |
All, Changed Behavior, CompatibilityPHP53, CompatibilityPHP54, CompatibilityPHP55, CompatibilityPHP56 |
Exakat since |
0.8.4 |
PHP Version |
With PHP 7.0 and older |
Severity |
Major |
Time To Fix |
Instant (5 mins) |
Precision |
Very high |
Available in |