Howto create session property?

29 views
Skip to first unread message

Ronny Buelund

unread,
Jun 10, 2025, 11:41:21 AMJun 10
to Joomla! General Development
I have used this in a plugin, to save some variables in the session:         
$this->session = Factory::getApplication()->getSession();

and then i use: 
$this->session->set('xxxxx.auth_state', '');
 $storedState = $this->session->get('xxxxx.auth_state', '');


But I get this warning:  
Creation of dynamic property xxxxxxx\Plugin\xxxxx\xxxxxx\Extension\xxxxxxxx::$session is deprecated

So how would I do that correct ?

Nicolas Claverie

unread,
Jun 11, 2025, 12:25:40 AMJun 11
to Joomla! General Development
It's a PHP issue not a Joomla issue.
You can't do $this->session in a class without first initializing it :
class MyClass {
 public $session = null; // that's what you're missing
 public myFunction() {
  $this->session = Factory::getApplication()->getSession();
 }
}

You can read more about it here:

Steven Berkson

unread,
Jun 11, 2025, 12:40:41 AMJun 11
to joomla-de...@googlegroups.com

Don’t you really want to use the built in session handling for Joomla with (application) state (getState, setState) and user state (getUserState, setUserState)?

 

https://docs.joomla.org/how_to_use_user_state_variables

--
You received this message because you are subscribed to the Google Groups "Joomla! General Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to joomla-dev-gene...@googlegroups.com.
To view this discussion, visit https://groups.google.com/d/msgid/joomla-dev-general/04e24d49-682f-488a-8804-f0cfb2fc747bn%40googlegroups.com.

Ronny Buelund

unread,
Jun 11, 2025, 1:21:59 AMJun 11
to joomla-de...@googlegroups.com
Thank you very much. I think that is exactly what i need😃

Reply all
Reply to author
Forward
0 new messages