Skip to content

Request::getSession return type should not be null #26539

@soullivaneuh

Description

@soullivaneuh
Q A
Bug report? no
Feature request? no
BC Break report? no
RFC? yes
Symfony version 4.0

As we have a hasSession method:

* @return bool true when the Request contains a Session object, false otherwise
*/
public function hasSession()
{
return null !== $this->session;
}

IMHO, getSession should not be nullable for the return type:

* @return SessionInterface|null The session
*/
public function getSession()
{
$session = $this->session;
if (!$session instanceof SessionInterface && null !== $session) {
$this->setSession($session = $session());
}
return $session;
}

It should throw an exception instead. Plus, thanks to PHP 7 type-hinting, throwing an exception will not be necessary in the future.

This will reduce some tools alerts like this:

Calling method set() on possibly null value of type Symfony\Component\HttpFoundation\Session\SessionInterface|null.

WDYT?

Metadata

Metadata

Assignees

No one assigned

    Labels

    HttpFoundationRFCRFC = Request For Comments (proposals about features that you want to be discussed)

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy