0

I get the error in the subject. Also I spent ages on google and found dozens of resources having the same error, but still I can't figure out what the issue is. This is my code:

<?php
if(empty(trim($_POST["user"])) || empty(trim($_POST["text"]))) {
    echo "no luck";
  }
?>

PHP Fatal error: Can't use function return value in write context in /var/www/test.php on on line 2

2
  • can you please explain little it more? 3v4l.org Commented May 7, 2016 at 10:02
  • 4
    Depending on PHP version empty() expects a variable reference, not an expression / function result. Use !strlen alternatively. Commented May 7, 2016 at 10:02

1 Answer 1

1

If you refer to a manual, you will see

Determine whether a variable is considered to be empty.

The result of trim passed to empty is not a variable.

So your options are:

$user = trim($_POST['user']);
if (!empty($user)) {   }

Or php5.5, in which

empty() now supports expressions

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.