Skip to content

\SessionHandlerInterface::read return type error #12748

Closed
phpstan/phpstan-src
#3884
@alexkart

Description

@alexkart

Bug report

In the following code $session = $sessionHandler->read('123'); PhpStan assumes that $session is string but it can be string or false according to PHP docs https://www.php.net/manual/en/sessionhandlerinterface.read.php

public SessionHandlerInterface::read(string $id): string|false

PhpStan generates the following error for this code:

if ($session === false) {
	return null;
}
Strict comparison using === between string and false will always evaluate to false.

Code snippet that reproduces the problem

https://phpstan.org/r/a1080965-9212-4b2a-af05-3ce9fa7734cc

Expected output

No errors.

Did PHPStan help you today? Did it make you happy in any way?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions