TheDeveloper / redis-session-php

34 stars 20 forks source link

RedisSession::start() Fatal Error #3

Open jordm opened 1 year ago

jordm commented 1 year ago

On PHP 8.1 I am getting issues connecting to redis through RedisSession

start-session.php:

// this must match the express-session `secret` in your Express app
define('EXPRESS_SECRET', 'test');

// this id mutator function helps ensure we look up
// the session using the right id
define('REDIS_SESSION_PREFIX', 'PHPREDIS_SESSION:');

...

require_once("redis-session-php/redis-session.php");

// Test PredisClient connection
$client = new Predis\Client([
    "scheme" => "tcp",
    "host" => "host.docker.internal",
    "port" => 6379,
    "password" => "test"
]);

$client->set("foo", "bar");

RedisSession::start([
    "scheme" => "tcp",
    "host" => "host.docker.internal",
    "port" => 6379,
    "password" => "test"
]);

$_SESSION["php"] = "Hello from PHP";
if (!isset($_SESSION["cookie"]))
  $_SESSION["cookie"] = array();

Looking at redis-cli, the output is:;

127.0.0.1:6379> keys *
1) "foo"

I'm getting the following error when running RedisSession::start():

php-dev    | NOTICE: PHP message: PHP Fatal error:  Uncaught TypeError: Session callback must have a return value of type bool, null returned in /var/www/php/src/redis-session-php/redis-session.php:47
php-dev    | Stack trace:
php-dev    | #0 /var/www/php/src/redis-session-php/redis-session.php(47): session_start()
php-dev    | #1 /var/www/php/src/start-session.php(55): RedisSession::start()
php-dev    | #2 /var/www/public/index.php(4): require_once('/var/www/php/sr...')
php-dev    | #3 {main}
php-dev    |   thrown in /var/www/php/src/redis-session-php/redis-session.php on line 47
jordm commented 1 year ago

Adding return true; to the open(), close(), and gc() methods solve this issue for PHP 8 forcing return types. But there is also an issue when passing null to json_decode now in the unserializer method