setcookie(): Passing null to parameter #7 ($httponly) of type bool is deprecated

Viewed 2826
public function csrf_set_cookie()
{
    $expire = time() + $this->_csrf_expire;
    $secure_cookie = (bool) config_item('cookie_secure');

    if ($secure_cookie && ! is_https())
    {
        return FALSE;
    }

    setcookie(
        $this->_csrf_cookie_name,
        $this->_csrf_hash,
        $expire,
        config_item('cookie_path'),
        config_item('cookie_domain'),
        $secure_cookie,
        config_item('cookie_httponly')
    );
    log_message('info', 'CSRF cookie sent');

    return $this;
}

Severity: 8192

Message: setcookie(): Passing null to parameter #7 ($httponly) of type > bool is deprecated

Filename: core/Security.php

1 Answers

As the warning says, you shouldn't be passing NULL to the httponly argument. You could use NULL-coalescing to pass an intelligent default if it's not defined in your configuration. E.g.:

setcookie(
    $this->_csrf_cookie_name,
    $this->_csrf_hash,
    $expire,
    config_item('cookie_path'),
    config_item('cookie_domain'),
    $secure_cookie,
    config_item('cookie_httponly') ?? true 
    # Here ------------------------^
);
Related