How to fix: Can’t use function return value in write context
After making an update to one of my WordPress plugins, when trying to load plugin settings page, I get the following error message:
Fatal error: Can’t use function return value in write context in /public_html/domain-name.com/wp-content/plugins/rss-feed-icon-for-specificfeedscom/inc/php/functional.php on line 19
For WordPress users, I recommend reading another article about this error.
What causes this error
This error message is self explanatory. It means that we are trying to use function to return value in write context. It also tells us where exactly this error occurred. To solve this issue, follow the steps below.
How to solve it
-
Open the file that is mentioned in the error message. In my case this is the
functional.php
file, which is placed in the/public_html/domain-name.com/wp-content/plugins/rss-feed-icon-for-specificfeedscom/inc/php/
directory. -
Find the line specified in the error message. In my case this is the 19th line.
-
Here you can see the code that causes the error. That’s how it looks in my case:
if ( ! empty( get_option( 'my_option' ) ) {
Note! You can see something similar to this but with
isset()
or another PHP function, and with custom function instead of WordPress functionget_option()
. For example:if ( ! empty( myFunction( $myVariable ) ) {
or:
if ( isset( $_POST( 'my_option' ) == TRUE ) ) {
All I had to do to solve this error was to change the code above to the following:
if ( ! get_option( 'my_option' ) )
This code does exactly the same thing but in more elegant way. Also we can make a variable and then use it in the our if
construction:
$my_option = get_option( 'my_option' );
if ( ! empty( $my_option ) {
Conclusion
That’s it, you’re done. Now your plugin should work without this error. So simple isn’t it?
If you are having trouble fixing this problem with the instructions above, but are being able to solve this problem with any another method please describe it in the comment section below. Thanks!
If this article has helped you solve the problem then please leave a comment
Thanks for reading!
Arthur is a designer and full stack software engineer. He is the founder of Space X-Chimp and the blog My Cyber Universe. His personal website can be found at arthurgareginyan.com.