1.2.278. Could Cast To Array¶
The array cast operator transform a scalar into an array with that scalar. It also keeps an array as an array, so a single call to (array)
is able to convert scalars to array, while keeping values already in array form intact.
<?php
//
if (!is_array($a)) {
$a = [$a];
}
// equivalent to
$a = (array) $a;
// same, with the else
if (is_array($a)) {
} else {
$a = array($a);
}
?>
See also Mastering the (array) Cast Operator in PHP.
1.2.278.1. Connex PHP features¶
1.2.278.1.1. Suggestions¶
Use a direct cast to array
1.2.278.1.2. Specs¶
Short name |
Structures/CouldCastToArray |
Rulesets |
|
Exakat since |
2.6.4 |
PHP Version |
All |
Severity |
Minor |
Time To Fix |
Quick (30 mins) |
Precision |
High |
Available in |