1.2.1111. Should Typecast¶
When typecasting, it is better to use the casting operator, such as (int)
or (bool)
.
Functions such as intval() or settype() are always slower. This is a micro-optimisation, although such conversion may be use multiple times, leading to a larger performance increase.
Note that intval() may also be used to convert an integer to another base. Intval() called with 2 arguments are skipped by this rule.
<?php
// Fast version
$int = (int) $X;
// Slow version
$int = intval($X);
// Convert to base 8 : can't use (int) for that
$int = intval($X, 8);
?>
1.2.1111.1. Connex PHP features¶
1.2.1111.1.1. Suggestions¶
Use a typecast, instead of a functioncall.
1.2.1111.1.2. Specs¶
Short name |
Type/ShouldTypecast |
Rulesets |
|
Exakat since |
0.8.4 |
PHP Version |
All |
Severity |
Minor |
Time To Fix |
Quick (30 mins) |
Precision |
High |
Examples |
|
Available in |