Using $this when not in object context

For Joomla! 3.x Coding related discussions, please use: http://groups.google.com/group/joomla-dev-general

Moderator: ooffick

Forum rules
Please use the mailing list here: http://groups.google.com/group/joomla-dev-general rather than this forum.
Post Reply
sazbaztaz
Joomla! Apprentice
Joomla! Apprentice
Posts: 44
Joined: Thu Mar 18, 2010 2:20 pm

Using $this when not in object context

Post by sazbaztaz » Sat Apr 13, 2019 11:30 am

I've created my own namespace and setting it up trough a system plugin which is working fine eg Foo::myfunction()...

Now I'd like to use $this as 90% of the times the functions within the namespace are using the JFactory::getUser(); for example and I want to set it up as $this->user = JFactory::getUser(); in the constructor so I don't have the repeat it all the time.

This must be a stupid question for most but why the error Using $this when not in object context when I try to call it.

I understand that I could go like... $foo = new Foo(); and then the constructor in the class fires but then again, wherever I want to call Foo::myFunction(); troughout Joomla I'd need to define a new object.

Is there a way to fire the constructor by just calling Foo::myFunction();

Post Reply

Return to “Joomla! 3.x Coding”