-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
Closed
Labels
HttpFoundationRFCRFC = Request For Comments (proposals about features that you want to be discussed)RFC = Request For Comments (proposals about features that you want to be discussed)
Milestone
Description
Q | A |
---|---|
Bug report? | no |
Feature request? | no |
BC Break report? | no |
RFC? | yes |
Symfony version | 4.0 |
As we have a hasSession
method:
symfony/src/Symfony/Component/HttpFoundation/Request.php
Lines 750 to 755 in 3e99988
* @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:
symfony/src/Symfony/Component/HttpFoundation/Request.php
Lines 719 to 729 in 3e99988
* @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?
florianajir
Metadata
Metadata
Assignees
Labels
HttpFoundationRFCRFC = Request For Comments (proposals about features that you want to be discussed)RFC = Request For Comments (proposals about features that you want to be discussed)