Connect with us

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


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

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.

Continue Reading
Click to comment

Leave a Reply

Your email address will not be published. Required fields are marked *

More in coding

About Me:

Szabi Kisded

Hey there, I'm Szabi. At 30 years old, I quit my IT job and started my own business and became a full time WordPress plugin developer, blogger and stay-at-home dad. Here I'm documenting my journey earning an online (semi)passive income. Read more

Sign up for my newsletter and get the YouTube Caption Scraper WordPress plugin for free
(worth 29$)!

All My Plugins In A Bundle:

My AutoBlogging Plugins:

My Online Courses:

A Theme I Recommend:

Featured Posts:

To Top