We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Session bug? Variable is "forgotten" right after putting in

Im using session through ->getDI and \Phalcon\DI::getDefault()->get('flash') way. But they seems to be different. Services.php:

$di->set('session', function() {
  $session = new Phalcon\Session\Adapter\Files();
  $session->start();
  return $session;
});

nothing special.

var_dump (\Phalcon\DI::getDefault()->get('flash')->getMessages());
var_dump($this->flashSession->getMessages());
var_dump (\Phalcon\DI::getDefault()->get('flash') == $this->flashSession);

so far its null; null, true. Everything is ok.

$this->flashSession->message('key2', 'val2');
var_dump (\Phalcon\DI::getDefault()->get('flash')->getMessages());
var_dump($this->flashSession->getMessages());

but now, the first dump has the values, while the 2nd DOES NOT! It returns a null.



3.3k
Accepted
answer

The method you use getMessages, removes the messages aswell. But check out the documentation, its 2nd param is called $remove, and it controls if it should remove the messages or not.