All of a sudden, my custom session handlers’ session’s session_start() is not working. I had to include destroy after upgrading to PHP 8. It isn’t an issue in PHP 7.4.
private static function load() { # session_module_name("user"); session_set_save_handler(['CBSession', 'open'], ['CBSession', 'close'], ['CBSession', 'read'], ['CBSession', 'write'], ['CBSession', 'remove'], ['CBSession', 'gc'], ['CBSession', 'destroy'] ); session_start(); // Error here } public static function destroy($id) { return TRUE; }
Fatal error: Uncaught ArgumentCountError: Too few arguments to function CBSession::destroy(), 0 passed and exactly 1 expected in Session.php: Stack trace: #0 [internal function]: CBSession::destroy() #1 /path/CB/Session.php(35): session_start() #2 /path/CB/Session.php(17): CBSession::load()
Why is it talking about session_destroy for session_start (login) ? My logout is working.
EDIT : For some reason CBSession::destroy() is getting called before session_start()
Advertisement
Answer
According to the session_set_save_handler manual page the arguments are:
- $open
- $close
- $read
- $write
- $destroy
- $gc
- (optional) $create_sid
- (optional) $validate_sid
- (optional) $update_timestamp
The method names you have provided are:
- ‘open’
- ‘close’
- ‘read’
- ‘write’
- ‘remove’
- ‘gc’
- ‘destroy’
So the method called for the session “destroy” event is CBSession::remove
, and the CBSession::destroy
method is being called for the “create_sid” event. Since the create_sid callback is called without any arguments, this is giving you the error you’re seeing.
At the beginning of your question you said:
I had to include destroy after upgrading to PHP 8.
Since what you’ve actually included is a broken create_sid callback, whatever problem you thought you were solving may still need solving, but that would be a different question. The solution to your current error is to remove the erroneous ['CBSession', 'destroy']
line from your code.