title: PHP 7.2 Warning: "Cannot change session name when session is active"
body: <p>Since PHP on our server was upgraded to 7.2 from 7.0. I am getting the following warning (which leads to error) if a new deployment is done. The reason is probably, that old sessions get invalid after deployment.</p>
  
  <blockquote>
    <p>Warning: session_name(): <strong>Cannot change session name when session is
    active in</strong> /var/www/html/model/login/lib/Session.class.php on line 137</p>
    
    <p>Warning: session_set_cookie_params(): <strong>Cannot change session cookie
    parameters when session is active in</strong>
    /var/www/html/model/login/lib/Session.class.php on line 138</p>
    
    <p>Warning: Cannot modify header information - headers already sent by
    (output started at
    /var/www/html/model/login/lib/Session.class.php:137) in
    /var/www/html/model/login/lib/Session.class.php on line 142</p>
  </blockquote>
  
  <p>It seems like PHP 7.2 got more strict in the context of session sin a certain context. The server seems to recognize the invalid sessions and tries to destroy those. This is part of the Session class:</p>
  
  <pre><code>/**
   * Secure instant destruction of session. Must be called after session_start !
   */
  public static function destroyAbsolute() {
  
      self::checkInit(); // unimportant
  
      session_name(self::$name); // this is line 137
      session_set_cookie_params(0, COOKIEPATH, null, self::$force_ssl_cookie, true);
  
      if(session_id()) {
          if (isset($_COOKIE[session_name()])) {
              setcookie(session_name(), "", time() - 42000, COOKIEPATH);
          }
          unset($_COOKIE[session_name()]);
          session_destroy();
      }
  }
  </code></pre>
  
  <p>What has changed in PHP regarding sessions? </p>
  
  <p>Why is it not allowed to set a session name if another session is active (<em>according to the docs with session_name I could change sessions and start multiple sessions</em>)?</p>
  
  <p>And how may I destroy the running session appropriately?</p>
  
  <p>Doing further research I also have found the following discussion on GitHub (<a href="https://github.com/Icinga/icingaweb2/issues/3185" rel="noreferrer">https://github.com/Icinga/icingaweb2/issues/3185</a>). <strong>They confirm that this error was introduced with PHP 7.2</strong>. Unfortunatly there is also no answer :-/</p>