1

If i try do something like this:

  $title = $this->fullSearchForm->get('title')->getValue();
            if(!empty($title)) {
                echo "ok";
            }

evrything is ok.

But i below case

 if(!empty($this->fullSearchForm->get('title')->getValue())) {
        echo "OK";
    }

I get error

Can't use method return value in write context in

My php is from debian stable Whezzy PHP 5.4.4-14+deb7u8 (cli) (built: Feb 17 2014 09:18:47) Thanks for answer

Costy
  • 165
  • 2
  • 14
  • Possible duplicate of http://stackoverflow.com/questions/1075534/cant-use-method-return-value-in-write-context – Quasdunk Apr 06 '14 at 11:57
  • below PHP 5.5 its not allowed !! U need to check empty() as in ur first case. Empty() only checks variables as anything else will result in a parse error – Abhik Chakraborty Apr 06 '14 at 11:58

1 Answers1

2

In your context, you should be using:

if( $this->fullSearchForm->get('title')->getValue()) {
    echo 'OK';
}

Because empty checks if a variable is set and not falsy, but a function's return value is always "set" so basically it's just a check for falsiness.

empty operates on variables, NOT functions.

Niet the Dark Absol
  • 320,036
  • 81
  • 464
  • 592