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.

Related:  12 Lead Capture WordPress Themes for Boosting Email Subscriptions & Signups
Continue Reading
You may also like...

We are a WordPress plugin developer company that focuses on useful WordPress plugin creation and empowering people to earn passive incomes from their blogs. We build unique and groundbreaking plugins that will revolutionize your blog!

Click to comment

Leave a Reply

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

More in coding

Sign up for our newsletter and get a free affiliate e-book!

About Me:

Szabi Kisded

Hi, my name is Szabi and I'm documenting my journey earning an online (semi)passive income. Learn more

Mega Plugin Bundle:

CodeCanyon Portfolio:

Online Courses:

Recommended Theme:

Popular Posts:

Latest Posts:

To Top