Dead code detection in PHP [closed]

xdebug‘s code coverage tools allow you to test which lines of code are actually being executed, without needing to put trace statements in all of the functions/methods.

Example:

<?php
    xdebug_start_code_coverage();

    function a($a) {
        echo $a * 2.5;
    }

    function b($count) {
        for ($i = 0; $i < $count; $i++) {
            a($i + 0.17);
        }
    }

    b(6);
    b(10);

    var_dump(xdebug_get_code_coverage());  // array '/path/file.php' => array line_number => int 1 or 0.
?>  

Leave a Comment