How can the issue of not having all parameters for bind_param() be addressed in PHP functions?

When using bind_param() in PHP functions, if not all parameters are provided, you can address this issue by dynamically building the parameter types and values array based on the number of parameters provided. This way, the function can handle different numbers of parameters without throwing errors.

function dynamic_bind_params($stmt, ...$params) {
    $types = '';
    $values = [];

    foreach($params as $param) {
        if(is_int($param)) {
            $types .= 'i';
        } elseif(is_float($param)) {
            $types .= 'd';
        } else {
            $types .= 's';
        }
        $values[] = $param;
    }

    $bind_params = array_merge([$types], $values);
    $bind_params_ref = [];
    foreach($bind_params as $key => $value) {
        $bind_params_ref[$key] = &$bind_params[$key];
    }

    call_user_func_array(array($stmt, 'bind_param'), $bind_params_ref);
}