Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Undefined offset: 0 error with get function in HttpFoundation/HeaderBag.php #35802

Closed
@frankgasking

Description

@frankgasking

Symfony version(s) affected: Latest build

Description
Symfony/Component/HttpFoundation/HeaderBag.php

The "get" function produces an "Undefined offset: 0" error if $headers is returned by the "all" function as an empty array.

If "all" is called and a key cannot be found in $this->headers, then [] is returned. However, this breaks line 116:
if (null === $headers[0]) {

How to reproduce

Call the get() function with a key that doesn't exist in the headers.

Possible Solution
Update line 112 from:

if (!$headers) {

to

if (!$headers || !isset($headers[0])) {

Additional context

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions