0

I have a class for working with the session, it inherits from an abstract class that has an array and a set() method that adds $key => $value data to the array. When I pass this array to $_SESSION by reference, the $_SESSION array is empty, why?

class SessionManager extends \AbstractSession
{
    public function __construct()
    {
        session_start();
        $this->data = &$_SESSION;
    }

Call set method

$this->sessionManager->setKey($_GET['key'])

Result sessionManager array

array (size=1)
  'key' => string '7831dc610922e7e0f84031b18b4ccc7d' (length=32)

and $_SESSION

array (size=0)
  empty

Get help in solving the problem

  • Make sure you're not getting the warning "Headers already sent" when you call `session_start()`. If you are, see https://stackoverflow.com/questions/8028957/how-to-fix-headers-already-sent-error-in-php for how to fix it. – Barmar Nov 14 '22 at 21:12

0 Answers0