Looking to Build/Redesign a Website or Blog ?

To speak to Rakshit, call +91 968 704 2303

[PHP] Fatal error: Can’t use method return value in write context

Hi,

Today while working with WordPress project, i got weird error message which is this. Fatal error: Can’t use method return value in write context.. I was working with one of the premium WordPress theme which client gave me and customize it according to client’s requests. It was working fire in local environment and when i completed the work and set up everything on live server, it throws the fatal error.

It was not hard to track the issue because it clearly indicates that you can’t use the method return value and also it mentions the line no. so it is easy for me to solve it quickly. Here is what theme functions.php file code was.

if(!empty(get_the_theme_funs($sel_var)){ return get_the_theme_funs($sel_var); }

You can not use the function inside “empty()” function. “empty()” function takes variable as parameters. It also apply to “isset()” function. You need to pass the variable as parameter. I have no clue why premium theme makes such mistakes. But here is corrected code.

$var_val = get_the_theme_funs($sel_var);
if(!empty($var_val){ return $var_val; }

As a solution, all you need to do is first take the response of any function in variable and than check the variable with empty() function or isset() function. I hope it helps and save your time. Thanks for reading.

Share: