bug #41495 [HttpFoundation] Add ReturnTypeWillChange to SessionHandlers (nikic)

This PR was squashed before being merged into the 4.4 branch.

Discussion
----------

[HttpFoundation] Add ReturnTypeWillChange to SessionHandlers

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | maybe?
| Tickets       |
| License       | MIT
| Doc PR        |
<!--
Replace this notice by a short README for your feature/bugfix. This will help people
understand your PR and can be used as a start for the documentation.

Additionally (see https://symfony.com/releases):
 - Always add tests and ensure they pass.
 - Never break backward compatibility (see https://symfony.com/bc).
 - Bug fixes must be submitted against the lowest maintained branch where they apply
   (lowest branches are regularly merged to upper ones so they get the fixes too.)
 - Features and deprecations must be submitted against branch 5.x.
 - Changelog entry should follow https://symfony.com/doc/current/contributing/code/conventions.html#writing-a-changelog-entry
-->

This adds `#[ReturnTypeWillChange]` annotations for `SessionHandler` methods to satisfy the [Tentative Return Types RFC](https://wiki.php.net/rfc/internal_method_return_types). This doesn't cover all classes (e.g. `MockPdo` is also affected), just the ones relating to `SessionHandler` etc.

It's worth noting that the `gc()` method is spec'd as `int|false` on our side, so I've updated type hints accordingly. The method used to return bool prior to PHP 7.1.

Commits
-------

8954b4f922 [HttpFoundation] Add ReturnTypeWillChange to SessionHandlers
This commit is contained in:
Alexander M. Turek 2021-06-01 21:14:33 +02:00
commit b439213767
3 changed files with 21 additions and 3 deletions

View File

@ -31,6 +31,7 @@ abstract class AbstractSessionHandler implements \SessionHandlerInterface, \Sess
/**
* @return bool
*/
#[\ReturnTypeWillChange]
public function open($savePath, $sessionName)
{
$this->sessionName = $sessionName;
@ -66,6 +67,7 @@ abstract class AbstractSessionHandler implements \SessionHandlerInterface, \Sess
/**
* @return bool
*/
#[\ReturnTypeWillChange]
public function validateId($sessionId)
{
$this->prefetchData = $this->read($sessionId);
@ -86,6 +88,7 @@ abstract class AbstractSessionHandler implements \SessionHandlerInterface, \Sess
/**
* @return string
*/
#[\ReturnTypeWillChange]
public function read($sessionId)
{
if (null !== $this->prefetchId) {
@ -109,6 +112,7 @@ abstract class AbstractSessionHandler implements \SessionHandlerInterface, \Sess
/**
* @return bool
*/
#[\ReturnTypeWillChange]
public function write($sessionId, $data)
{
if (null === $this->igbinaryEmptyData) {
@ -126,6 +130,7 @@ abstract class AbstractSessionHandler implements \SessionHandlerInterface, \Sess
/**
* @return bool
*/
#[\ReturnTypeWillChange]
public function destroy($sessionId)
{
if (!headers_sent() && filter_var(ini_get('session.use_cookies'), \FILTER_VALIDATE_BOOLEAN)) {

View File

@ -33,6 +33,7 @@ class StrictSessionHandler extends AbstractSessionHandler
/**
* @return bool
*/
#[\ReturnTypeWillChange]
public function open($savePath, $sessionName)
{
parent::open($savePath, $sessionName);
@ -51,6 +52,7 @@ class StrictSessionHandler extends AbstractSessionHandler
/**
* @return bool
*/
#[\ReturnTypeWillChange]
public function updateTimestamp($sessionId, $data)
{
return $this->write($sessionId, $data);
@ -67,6 +69,7 @@ class StrictSessionHandler extends AbstractSessionHandler
/**
* @return bool
*/
#[\ReturnTypeWillChange]
public function destroy($sessionId)
{
$this->doDestroy = true;
@ -88,14 +91,16 @@ class StrictSessionHandler extends AbstractSessionHandler
/**
* @return bool
*/
#[\ReturnTypeWillChange]
public function close()
{
return $this->handler->close();
}
/**
* @return bool
* @return int|false
*/
#[\ReturnTypeWillChange]
public function gc($maxlifetime)
{
return $this->handler->gc($maxlifetime);

View File

@ -38,6 +38,7 @@ class SessionHandlerProxy extends AbstractProxy implements \SessionHandlerInterf
/**
* @return bool
*/
#[\ReturnTypeWillChange]
public function open($savePath, $sessionName)
{
return (bool) $this->handler->open($savePath, $sessionName);
@ -46,6 +47,7 @@ class SessionHandlerProxy extends AbstractProxy implements \SessionHandlerInterf
/**
* @return bool
*/
#[\ReturnTypeWillChange]
public function close()
{
return (bool) $this->handler->close();
@ -54,6 +56,7 @@ class SessionHandlerProxy extends AbstractProxy implements \SessionHandlerInterf
/**
* @return string
*/
#[\ReturnTypeWillChange]
public function read($sessionId)
{
return (string) $this->handler->read($sessionId);
@ -62,6 +65,7 @@ class SessionHandlerProxy extends AbstractProxy implements \SessionHandlerInterf
/**
* @return bool
*/
#[\ReturnTypeWillChange]
public function write($sessionId, $data)
{
return (bool) $this->handler->write($sessionId, $data);
@ -70,22 +74,25 @@ class SessionHandlerProxy extends AbstractProxy implements \SessionHandlerInterf
/**
* @return bool
*/
#[\ReturnTypeWillChange]
public function destroy($sessionId)
{
return (bool) $this->handler->destroy($sessionId);
}
/**
* @return bool
* @return int|false
*/
#[\ReturnTypeWillChange]
public function gc($maxlifetime)
{
return (bool) $this->handler->gc($maxlifetime);
return $this->handler->gc($maxlifetime);
}
/**
* @return bool
*/
#[\ReturnTypeWillChange]
public function validateId($sessionId)
{
return !$this->handler instanceof \SessionUpdateTimestampHandlerInterface || $this->handler->validateId($sessionId);
@ -94,6 +101,7 @@ class SessionHandlerProxy extends AbstractProxy implements \SessionHandlerInterf
/**
* @return bool
*/
#[\ReturnTypeWillChange]
public function updateTimestamp($sessionId, $data)
{
return $this->handler instanceof \SessionUpdateTimestampHandlerInterface ? $this->handler->updateTimestamp($sessionId, $data) : $this->write($sessionId, $data);