Joomla issue - "$this->items = $this->get('Items'); does not work anymore under PHP 7.1 and 7.2

by Andreas Isele   Last Updated January 04, 2018 17:10 PM - source

In my component I am assigning the data from the model to the view using

class FileUploaderViewFileUploader extends JViewLegacy
// Overwriting JView display method
function display($tpl = null)
// Assign data to the view
$this->items = $this->get('Items'); // => This causes the error
// Display the view

The error at my website I get is:
Error: 0
Using $this when not in object context

Anybody an idea what happened here? This code worked well under PHP 5.6.x as well as PHP 7.0.26.
Thank you in advance.

Best regards

Tags : php7

Answers 2

Are you sure the error is coming from that line? If so, you may want to review your model's getItems method (include it also in your question for review). Likely you might be calling a static method somewhere, where you can't use $this.

Also, what is your Joomla version - is it up-to-date? Have you just updated Joomla? Are you sure the update went smoothly? Note that this error might be coming from anywhere... e.g. a plugin, or core code if an update didn't completed successfully.

Enable error reporting and debug and see what else information you get from there.

January 04, 2018 19:11 PM

Found the issue. I called JSite in my model.

I changed it to:

$app = JFactory::getApplication(); 
$menu = $app->getMenu();

This fixed the issue.

Andreas Isele
Andreas Isele
December 04, 2018 16:33 PM

Related Questions

A PHP 7 question concerning =&

Updated June 08, 2017 15:10 PM

different templates based on $item number

Updated February 17, 2018 15:10 PM

Upgrade PHP to 7.2 cause error

Updated October 28, 2018 14:10 PM