has($key, $defaultValue); $this->delete($key); return $value; } /** * Key to retrieve. * * @param string|int $key The key to retrieve. * @param mixed $defualtValue The defualt value to return. * * @return mixed Can return all value types. */ public function get(string|int $key, mixed $defaultValue = null): mixed { return $this->has($key) ? $_SESSION[$key] : $defualtValue; } /** * This iterator allows to unset and modify values and keys while iterating over Arrays and Objects. * Type-Hints are not needed for this method. * * @return void No value is returned. */ public function getIterator() { return new ArrayIterator($_SESSION); } /** * Whether a key exists. * * @param string|int $key A key to check for. * * @return bool Returns true on success or false on failure. */ public function has(string|int $key): bool { return isset($_SESSION[$key]); } /** * Whether an offset exists. * Type-Hints are not needed for this method. * * @param mixed $offset An offset to check for. * * @return bool Returns true on success or false on failure. */ public function offsetExists($offset) { return $this->has($offset); } /** * Offset to retrieve. * Type-Hints are not needed for this method. * * @param mixed $offset The offset to retrieve. * * @return mixed Can return all value types. */ public function offsetGet($offset) { return $this->get($offset); } /** * Assign a value to the specified offset. * Type-Hints are not needed for this method. * * @param mixed $offset The offset to assign the value to. * @param mixed $value The value to set. * * @return void No value is returned. */ public function offsetSet($offset, $value) { $this->set($offset, $value); } /** * Unset an offset. * Type-Hints are not needed for this method. * * @param mixed $offset The offset to unset. * * @return void No value is returned. */ public function offsetUnset($offset) { $this->delete($offset); } /** * Assign a value to the specified key. * * @param string|int $key The key to assign the value to. * @param mixed $value The value to set. * * @return void No value is returned. */ public function set(string|int $key, mixed $value): void { $_SESSION[$key] = $value; } }