Repository: symfony/symfony
File: src/Symfony/Component/HttpFoundation/Request.php (PHP)

Code before:
                return self::STRUCTURED_SUFFIX_FORMATS[$suffix];
            }
        }

        if ($subtypeFallback && str_contains($canonicalMimeType, '/')) {
            [, $subtype] = explode('/', $canonicalMimeType, 2);
            if (str_starts_with($subtype, 'x-')) {
                $subtype = substr($subtype, 2);
            }
            if (!str_contains($subtype, '+')) {
                return $subtype;
            }
        }

        return null;
    }

    /**
     * Associates a format with mime types.
     *
     * @param string          $format    The format to set
     * @param string|string[] $mimeTypes The associated mime types (the preferred one must be the first as it will be used as the content type)
     */
    public function setFormat(?string $format, string|array $mimeTypes): void
    {
        if (null === $format) {
            trigger_deprecation('symfony/http-foundation', '7.4', 'Passing "null" as the first argument of "%s()" is deprecated. The argument will be non-nullable in Symfony 8.0.', __METHOD__);
        }

        if (null === static::$formats) {
            static::initializeFormats();
        }

        static::$formats[$format ?? ''] = (array) $mimeTypes;
    }

    /**
     * Gets the request format.
     *
     * Here is the process to determine the format:
     *
     *  * format defined by the user (with setRequestFormat())
     *  * _format request attribute
     *  * $default
     *
     * @see getPreferredFormat
     */
    public function getRequestFormat(?string $default = 'html'): ?string
    {
        $this->format ??= $this->attributes->get('_format');


Review comment (suggestion):
let's set the arg to the empty string inside the "if" and remove the ?? below
also don't miss updating the changelog file of the component

Code after:
                return self::STRUCTURED_SUFFIX_FORMATS[$suffix];
            }
        }

        if ($subtypeFallback && str_contains($canonicalMimeType, '/')) {
            [, $subtype] = explode('/', $canonicalMimeType, 2);
            if (str_starts_with($subtype, 'x-')) {
                $subtype = substr($subtype, 2);
            }
            if (!str_contains($subtype, '+')) {
                return $subtype;
            }
        }

        return null;
    }

    /**
     * Associates a format with mime types.
     *
     * @param string          $format    The format to set
     * @param string|string[] $mimeTypes The associated mime types (the preferred one must be the first as it will be used as the content type)
     */
    public function setFormat(?string $format, string|array $mimeTypes): void
    {
        if (null === $format) {
            trigger_deprecation('symfony/http-foundation', '7.4', 'Passing "null" as the first argument of "%s()" is deprecated. The argument will be non-nullable in Symfony 8.0.', __METHOD__);
            $format = '';
        }

        if (null === static::$formats) {
            static::initializeFormats();
        }

        static::$formats[$format] = (array) $mimeTypes;
    }

    /**
     * Gets the request format.
     *
     * Here is the process to determine the format:
     *
     *  * format defined by the user (with setRequestFormat())
     *  * _format request attribute
     *  * $default
     *
     * @see getPreferredFormat
     */
    public function getRequestFormat(?string $default = 'html'): ?string
    {
        $this->format ??= $this->attributes->get('_format');