Exakat 1.2.6 review

Exakat 1.2.6 got its review! This is all about the schizophrenic arrayunique() situation, since we have both ‘Avoid arrayunique()’ and ‘shoul use array_unique()’ in the same engine! Also, we added zookeeper. It’s the short Exakat 1.2.6 review.

array_unique() situation

Arrayunique() has been the target of an analysis until PHP 7.2, as it used to be needlessly slow. Apparently, not only arrayunique() extract unique values in an array, but it also applied some sorting, leading to poor performances. This has been fixed in PHP 7.2, and as such, Exakat doesn’t report it as a performance sinkhole when the audit is run against this PHP version.

And, in PHP 1.2.6, exakat introduces a new analysis that suggests using arrayunique(). So, we are now both recomending and warning people against arrayunique. That’s fun.

In fact, array_unique() is often reinvented. It may be a side-effect of the previous situation, or a simple overview of the native capabilities of PHP. You may run into that kind of code :

<?php

$unique = array();
foreach($array as $k => $v) {
    if (!in_array($v, $unique)) {
        $unique[] = $v;
    }
}

$unique = array();
foreach($array as $k => $v) {
    if (!isset($unique[$v])) {
        $unique[$v] = 1;
    }
}

?>

 

Both are slower and less readable than the native PHP function. They are also more work.

Finally, the analysis finds some loops that build the unique array, and perform extra tasks. It might be a good idea to review that structure, and break it into two : one with array_unique() and one with the rest of the loop.

ext/zookeeper

PHP has an extension for binding with zookeeper server. ZooKeeper is a distributed, open-source coordination service for distributed applications. It is an Apache software project. You can use it off-the-shelf to implement consensus, group management, leader election, and presence protocols.

Exakat now recognize zookeeper in the code.

Happy PHP code reviews

All the 344 analyzers are presented in the docs, including the panicky Unknown Directive Name : it reports unknown directives being used in the code. If you ever had problems with spelling ‘shortopentag’ or ‘error_display’, then you are among the 9% that are falling for this. Exakat include directives for 145 PHP extensions : feel free to ping us.

You can check all of the exakat reports at the gallery: exakat gallery.

Download Exakat on exakat.io, install it with Docker, upgrade it with ‘exakat.phar upgrade -u’ and like us on github.