Back to Session class

Method clear

public void
clear
()
Clears all variables from the session store
Returns
  • void
Since
  • 1.5
Class: Session
Project: Joomla

Method clear - Source code

/**
 * Clears all variables from the session store
 *
 * @return  void
 *
 * @since   1.5
 */
public function clear()
{
    // Handle B/C by checking if parameters were passed to this method; if so proxy to the new remove() method, will be removed at 5.0
    if (\func_num_args() >= 1) {
        $args = \func_get_args();
        if (!empty($args[0])) {
            @trigger_error('Using ' . __METHOD__ . '() to remove a single element from the session is deprecated.  Use ' . __CLASS__ . '::remove() instead.', E_USER_DEPRECATED);
            $name = $args[0];
            // Also check for a namespace
            if (\func_num_args() > 1 && !empty($args[1])) {
                @trigger_error('Passing a namespace as a parameter to ' . __METHOD__ . '() is deprecated. ' . 'The namespace should be prepended to the name instead.', E_USER_DEPRECATED);
                $name = $args[1] . '.' . $name;
            }
            $this->remove($name);
            /*
             * B/C for cleaning sessions that originated in Joomla 3.
             * A namespace before Joomla 4 has a prefix of 2 underscores (__).
             * This is no longer the case in Joomla 4 so we clean both variants.
             */
            $this->remove('__' . $name);
            return;
        }
    }
    parent::clear();
}