0

Using PHP5.3, I can use a function directly in a condition,like this :

if(my_function($var) == 'hello') {...}

But sometimes, even if I know what the function would return, I have a PHP bug and I have to do like this :

$result = another_function($var);
if($result == 'world') {...}

If both functions would return a string, why can I use the first and not the second ? I want to understand what the if condition can accept. Are all PHP natives functions are ok ? does the if condition doesn't want a method MyObject->my_function($var) ?

Alireza Fallah
  • 4,609
  • 3
  • 31
  • 57
Meowcate
  • 371
  • 1
  • 4
  • 12
  • 1
    can we see the functions ? what error do you get ? – Alireza Fallah Jan 03 '14 at 10:25
  • is this the error you are seeing? http://stackoverflow.com/questions/1075534/cant-use-method-return-value-in-write-context – WayneC Jan 03 '14 at 10:30
  • Like WayneC shows me, it's not about the condition but a limitation of empty(). Because It's always used in conditions I though others functions can have the same problem, thanks for that. – Meowcate Jan 03 '14 at 10:37

0 Answers0