Fatal error: Can't use method return value in write context

by RustyJoomla   Last Updated January 13, 2018 12:10 PM

I have written a module to display images on my site, but I'm getting the following error on the site:

Fatal error: Can't use method return value in write context in /public_html/camps/modules/mod_slider/mod_slider.php on line 24

This is what is showing on line 24:

<?php if (!empty($params->get('image-1')) || !empty($params->get('image-1-alt')) || !empty($params->get('image-1-caption'))) { ?>

Any ideas what's gone wrong?

The server is running PHP version 5.3.10-1ubuntu3.15

Tags : php


Answers 3


Prior to PHP 5.5, the function empty() can only be used on variables, not return values, so you have to approach it like this:

$image = $params->get('image-1');
$alt = $params->get('image-1-alt');
$caption = $params->get('image-1-caption');
if (!empty($image) || !empty($alt) || !empty($caption)) {
GDP
GDP
December 05, 2014 14:19 PM

Just a little addition to @GDP's answer.

Instead of checking whether the variables are empty or not, you could set default values for them like so:

$image   = $params->get('image-1', 'images/image.png');
$alt     = $params->get('image-1-alt', 'Generic Alt');
$caption = $params->get('image-1-caption', 'Generic Caption');

Then simply create a generic image that will show is nothing has been set.

Lodder
Lodder
December 05, 2014 14:45 PM

Change your php version to 5.6 and waiting for apply by your web hosting server.

Frankie
Frankie
January 13, 2018 11:49 AM

Related Questions