0

Suppose I've a PHP function returning some values.

<?php
function wpse_20131026() {
  $var = "I'm a function";
  return $var;
}
?>

How can I check whether it's returning empty or not? I tried the following:

<?php
if( !empty( wpse_20131026() ) ) {
  //do_something;
}
?>

But it's warning me:

Fatal error: Can't use function return value in write context

1
  • Also, read this useful topic: kunststube.net/isset Commented Oct 26, 2013 at 12:29

1 Answer 1

3

empty() checks variables, but not values in php versions, that less than 5.5.

Prior to PHP 5.5, empty() only supports variables; anything else will result in a parse error. In other words, the following will not work: empty(trim($name)). Instead, use trim($name) == false.

So you may use a temporary variable:

$var = wpse_20131026();

if(!empty($var)) {
    // do_something with $var
}

Or boolean evaluation directly (without empty() call):

if(wpse_20131026()) {
    // do_something
}
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.