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

fishmong3r
  • 1,414
  • 4
  • 24
  • 51
  • can you please explain little it more? [3v4l.org](https://3v4l.org/YDgKn) – Murad Hasan May 07 '16 at 10:02
  • 4
    Depending on PHP version `empty()` expects a variable reference, not an expression / function result. Use `!strlen` alternatively. – mario May 07 '16 at 10:02

1 Answers1

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

u_mulder
  • 54,101
  • 5
  • 48
  • 64