PHP

PHP

Made by DeepSource

Consider using func_num_args PHP-P1001

Performance
Minor

Instead of using func_get_args() with count() function, consider using PHP's built-in function func_num_args() to count number of arguments of the function.

This is a micro-optimization. Apply it in case of intensive usage.

Bad practice

function sql_substr($expr, $start = 1, $length = false) {
    if (count(func_get_args()) < 2) {
        return '';
    }

    if ($length === false) {
        return "SUBSTR($expr, $start)";
    } else {
        return "SUBSTR($expr, $start, $length)";
    }
}

Recommended

function sql_substr($expr, $start = 1, $length = false) {
    if (func_num_args() < 2) {
        return '';
    }

    if ($length === false) {
        return "SUBSTR($expr, $start)";
    } else {
        return "SUBSTR($expr, $start, $length)";
    }
}