I have this SessionService.php file that handles session_start
and session_regenerate_id
functions.
I make use of an abstract class that generates a new session ID and stores it in a variable called $new_session_id
. Then I return this variable as an argument of an abstract function called returnNewSessionID()
, contained in the class SessionRegenerateID
. This abstract function is designed to return the variable $new_session_id
.
That's where the problem is. Instead of returning a string (the new session ID we generated), it returns NULL.
At createNewID()
, you see I am assigning the newly generated code to a session variable called $_SESSION['new_session_id']
. By echoing this session variable, I get the expected value from it. At the same time, echoing the returned value from the createNewID()
function gives me NULL
.
The ID is being generated. The problem most likely lies in the way this variable $new_session_id
is being used inside these functions. I need to figure out why it is not being returned by the abstract function.
SessionService.php
interface SessionRegenerateInterface {
public function createNewID();
(... other unrelated functions ...)
}
abstract class AbstractSessionRegenerate implements SessionRegenerateInterface {
public function createNewID() {
$new_session_id = session_create_id();
$_SESSION['new_session_id'] = $new_session_id;
$this->returnNewSessionID($new_session_id);
}
abstract protected function returnNewSessionID($newID);
}
class SessionRegenerateID extends AbstractSessionRegenerate {
protected function returnNewSessionID($newID) {
return $newID;
}
}
SessionController.php
$RegenerateSession = new SessionRegenerateID;
$newID = $RegenerateSession->createNewID();
var_dump($newID); // outputs NULL
var_dump($_SESSION['new_session_id']); // outputs the generated session ID
I have an InputValidation class which is logically identical to this one, except for the type of value it returns: TRUE or FALSE. It works. But now that I am passing a variable with a string value, it returns NULL. I appreciate help to understand why.