Skip to content

Commit

Permalink
bug #41495 [HttpFoundation] Add ReturnTypeWillChange to SessionHandle…
Browse files Browse the repository at this point in the history
…rs (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
-------

8954b4f [HttpFoundation] Add ReturnTypeWillChange to SessionHandlers
  • Loading branch information
derrabus committed Jun 1, 2021
2 parents ca61cd6 + 8954b4f commit b439213
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
Expand Up @@ -31,6 +31,7 @@ abstract class AbstractSessionHandler implements \SessionHandlerInterface, \Sess
/**
* @return bool
*/
#[\ReturnTypeWillChange]
public function open($savePath, $sessionName)
{
$this->sessionName = $sessionName;
Expand Down Expand Up @@ -66,6 +67,7 @@ abstract protected function doDestroy($sessionId);
/**
* @return bool
*/
#[\ReturnTypeWillChange]
public function validateId($sessionId)
{
$this->prefetchData = $this->read($sessionId);
Expand All @@ -86,6 +88,7 @@ public function validateId($sessionId)
/**
* @return string
*/
#[\ReturnTypeWillChange]
public function read($sessionId)
{
if (null !== $this->prefetchId) {
Expand All @@ -109,6 +112,7 @@ public function read($sessionId)
/**
* @return bool
*/
#[\ReturnTypeWillChange]
public function write($sessionId, $data)
{
if (null === $this->igbinaryEmptyData) {
Expand All @@ -126,6 +130,7 @@ public function write($sessionId, $data)
/**
* @return bool
*/
#[\ReturnTypeWillChange]
public function destroy($sessionId)
{
if (!headers_sent() && filter_var(ini_get('session.use_cookies'), \FILTER_VALIDATE_BOOLEAN)) {
Expand Down
Expand Up @@ -33,6 +33,7 @@ public function __construct(\SessionHandlerInterface $handler)
/**
* @return bool
*/
#[\ReturnTypeWillChange]
public function open($savePath, $sessionName)
{
parent::open($savePath, $sessionName);
Expand All @@ -51,6 +52,7 @@ protected function doRead($sessionId)
/**
* @return bool
*/
#[\ReturnTypeWillChange]
public function updateTimestamp($sessionId, $data)
{
return $this->write($sessionId, $data);
Expand All @@ -67,6 +69,7 @@ protected function doWrite($sessionId, $data)
/**
* @return bool
*/
#[\ReturnTypeWillChange]
public function destroy($sessionId)
{
$this->doDestroy = true;
Expand All @@ -88,14 +91,16 @@ protected function doDestroy($sessionId)
/**
* @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);
Expand Down
Expand Up @@ -38,6 +38,7 @@ public function getHandler()
/**
* @return bool
*/
#[\ReturnTypeWillChange]
public function open($savePath, $sessionName)
{
return (bool) $this->handler->open($savePath, $sessionName);
Expand All @@ -46,6 +47,7 @@ public function open($savePath, $sessionName)
/**
* @return bool
*/
#[\ReturnTypeWillChange]
public function close()
{
return (bool) $this->handler->close();
Expand All @@ -54,6 +56,7 @@ public function close()
/**
* @return string
*/
#[\ReturnTypeWillChange]
public function read($sessionId)
{
return (string) $this->handler->read($sessionId);
Expand All @@ -62,6 +65,7 @@ public function read($sessionId)
/**
* @return bool
*/
#[\ReturnTypeWillChange]
public function write($sessionId, $data)
{
return (bool) $this->handler->write($sessionId, $data);
Expand All @@ -70,22 +74,25 @@ public function write($sessionId, $data)
/**
* @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);
Expand All @@ -94,6 +101,7 @@ public function validateId($sessionId)
/**
* @return bool
*/
#[\ReturnTypeWillChange]
public function updateTimestamp($sessionId, $data)
{
return $this->handler instanceof \SessionUpdateTimestampHandlerInterface ? $this->handler->updateTimestamp($sessionId, $data) : $this->write($sessionId, $data);
Expand Down

0 comments on commit b439213

Please sign in to comment.