1.2.98. Can’t Count Non-Countable¶
Count() emits an error when it tries to count scalars or objects what don’t implement Countable interface.
<?php
// Normal usage
$a = array(1,2,3,4);
echo count($a)." items\n";
// Error emiting usage
$a = '1234';
echo count($a)." chars\n";
// Error emiting usage
echo count($unsetVar)." elements\n";
?>
See also Warn when counting non-countable types.
1.2.98.1. Connex PHP features¶
1.2.98.1.1. Suggestions¶
Add a check before using count such as a type check
1.2.98.1.2. Specs¶
Short name |
Structures/CanCountNonCountable |
Rulesets |
|
Exakat since |
1.0.4 |
PHP Version |
All |
Severity |
Major |
Time To Fix |
Quick (30 mins) |
Precision |
Very high |
Available in |