1.2.1140. Slow Functions¶
Avoid using those slow native PHP functions, and replace them with alternatives. +—————————————————————+—————————————————————————————————————————-+ | Slow Function | Faster | +—————————————————————+—————————————————————————————————————————-+ | array_diff() | foreach() | | array_intersect() | foreach() | | array_key_exists() | isset() and array_key_exists() | | array_map() | foreach() | | array_search() | array_flip() and isset() | | array_udiff() | Use another way | | array_uintersect() | Use another way | | array_unshift() | Use another way | | array_walk() | foreach() | | in_array() | isset() | | preg_replace() | strpos() | | strstr() | strpos() | | uasort() | Use another way | | uksort() | Use another way | | usort() | Use another way | | array_unique() | array_keys() and array_count_values() | +—————————————————————+—————————————————————————————————————————-+
array_unique() has been accelerated in PHP 7.2 and may be used directly from this version on : Optimize `array_unique() <https://github.com/php/php-src/commit/6c2c7a023da4223e41fea0225c51a417fc8eb10d>`_.
array_key_exists() has been accelerated in PHP 7.4 and may be used directly from this version on : Implement ZEND_ARRAY_KEY_EXISTS opcode to speed up `array_key_exists() <https://github.com/php/php-src/pull/3360>`_.
<?php
$array = source();
// Slow extraction of distinct values
$array = array_unique($array);
// Much faster extraction of distinct values
$array = array_keys(array_count_values($array));
?>
1.2.1140.1. Suggestions¶
Replace the slow function with a faster version
Remove the usage of the slow function
1.2.1140.2. Specs¶
Short name |
Performances/SlowFunctions |
Rulesets |
|
Exakat since |
0.8.4 |
PHP Version |
All |
Severity |
Major |
Time To Fix |
Quick (30 mins) |
Precision |
Very high |
ClearPHP |
|
Examples |
|
Available in |