public function isValidId(?string $id): bool
    {
        if ($id == '') {
            return false;
        }

        if ($this->saveHandler != null && method_exists($this->saveHandler, 'isValidId')) {
            return $this->saveHandler->isValidId($id);
        }

        static $idPattern;
        if ($idPattern == null) {
            if ($this->options['hash']) {
                $idPattern = '~^[A-F0-9]{'. $this->options['hashLength'] .'}$~';
            } else {
                // @see http://php.net/manual/en/session.configuration.php#ini.session.sid-length
                // @see http://php.net/manual/en/session.configuration.php#ini.session.sid-bits-per-character
                // @see https://github.com/php/php-src/blob/PHP-7.1/UPGRADING#L114
                $idLength = ini_get('session.sid_length') ?: self::SID_LENGTH;
                $idBitsPerCharacter = ini_get('session.sid_bits_per_character');
                if ($idBitsPerCharacter == '') { // never happens, but obsession..
                    ini_set('session.sid_length', (string) self::SID_LENGTH);
                    ini_set('session.sid_bits_per_character', (string) ($idBitsPerCharacter = self::SID_BITSPERCHARACTER));
                }

                $idCharacters = '';
                switch ((int) $idBitsPerCharacter) {
                    case 4: $idCharacters = '0-9a-f'; break;
                    case 5: $idCharacters = '0-9a-v'; break;
                    case 6: $idCharacters = '0-9a-zA-Z-,'; break;
                }

                $idPattern = '~^['. $idCharacters .']{'. $idLength .'}$~';
            }
        }

        return (bool) preg_match($idPattern, $id);
    }