1.2.845. No Valid Cast¶
This cast generates an error, as there is no way to convert an object to an int.
The result will be 1.
This rule applies to float and int. This doesn’t apply to string cast, as the magic method __toString() allows for such conversions.
<?php
$a = (int) foo();
function foo() : A {}
?>
1.2.845.2. Connex PHP features¶
1.2.845.2.1. Suggestions¶
Create a method that convert the original object to the target type
1.2.845.2.2. Specs¶
Short name |
Structures/NoValidCast |
Rulesets |
|
Exakat since |
2.5.2 |
PHP Version |
All |
Severity |
Minor |
Time To Fix |
Quick (30 mins) |
Precision |
Medium |
Available in |