Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

davestewart's avatar

Set session weirdness in AppServiceProvider

I'm trying to do something fairly basic; set a session variable in the AppServiceProvider. The value will be used by a 3rd-party package (that I'm writing) that loads later to override some of its settings.

This works, in the boot process, but if I dump the session in a controller later, the session value NEVER changes after its initial set!

// AppServiceProvider
public function boot()
{
    dump(\Session::get('test'));
    \Session::put('test', microtime()); // won't update on subsequent requests
    dump(\Session::get('test'));
}

// Package
public function init ()
{
    $value = \Session::get('test'); // gets the correct value
}

// Controller
public function dumpSession ()
{
    print_r(\Session::all()); // only the first-set value ever shows, never an updated value!
}

It's very strange; I can't trust my session.

Am I missing something?

0 likes
1 reply
davestewart's avatar
davestewart
OP
Best Answer
Level 11

OK, testing in 5.4 and this seems to be OK. I figure a bug in 5.2 then.

Please or to participate in this conversation.