My fix to`0 – Using $this not in object context` in Joomla!

After migrating, the Joomla! page would not show up. Instead, only the error “0 – Using $this not in object context” was showing up. In my case, I was able to fix the issue by replacing – in the code of the template – all JFactory::getMenu() with $application->getMenu(), where $application came from $application = JFactory::getApplication().

Note that this may not be the only possible fix for this error. It highly depends on the code you have. Generally, the errormessage indicates the underlying problem: somewhere in Joomla!s code, there is a $this inside a class which – in your code – is used, without the class being instantiated properly. In the case mentioned above, the class is initialized statically. This, because that was valid apparently in elder Joomla! versions.

To find the source of your problem, I recommend to enable Joomla! debugging as well as PHP logging in order to get the full stack trace and find the origin of the wrongly instantiated class.

Tim Bernhard

Mein Name ist Tim Bernhard, geboren bin ich am 2. August 1996. Ich besuchte die Kantonsschule in Wiedikon und schloss diese im Frühling 2015 ab. Als Maturaarbeit habe ich meine Leidenschaft für Programmiertechnische Projekte mit Hoffnungen für die Zukunft verbunden und das Unternehmen Bernhard Webstudio gegründet.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.