I have a custom PHP session handler. In PHP 8.6 I get the following messages in my error log:
PHP Deprecated: session_set_save_handler(): Providing an object to argument #1 ($sessionhandler) which does not have the create_sid() method defined is deprecated
PHP Warning: Class MyNamespace\SessionHandlerDb implementing SessionHandlerInterface is missing the create_sid() method which will be required in PHP 9.0
I had imagined that I would need to provide the create_sid() method and write my own code that generates a session id respecting the session.sid_length and session.sid_bits_per_character ini settings. However it turns out that simply adding
public function create_sid(): string
{
return session_create_id();
}
seems to work. But why? I had expected this to result in an infinite recursive loop with session_create_id() eventually calling create_sid(). And should create_sid() also check that the sid doesn't already exist? For example:
public function create_sid(): string
{
$id = session_create_id();
return ($this->validateId($id)) ? $this->create_sid() : $id;
}
Finally, having generated the session id, should create_sid() add it to the sessions table (I've implemented a custom DB session handler)?
I'm obviously missing something, but the PHP manual for create_sid() isn't very clear.