I just found out another very strange thing I cannot explain properly:
Whenever you have a function, you mostly want to check the value it returns.
|
|
|
<?php
function true_val() { return true; }
$x = true_val();
if ($x) echo "true";1
?>
|
This is quite normal.
show me
|
|
  |
|
|
<?php
function true_val() { return true; }
if (!empty(true_val())) echo "true1";
if (isset(true_val())) echo "true2";
?>
|
But sometimes your function might return something that is empty. So, let's check this.
Surprise: it does not work. You get an parse error (depending on the PHP version you get either
expecting `T_VARIABLE' or `'$'' or expecting ")")
show me
Why does this happen? Normally, the result of a function is stored somewhere locally in a temporary space,
so that you can easily check it. I could even understand, when it is said, that these temporary variables
cannot be checked for emptiness or if they are set.
But what should the error message help then? How should I fix the error, when the interpreter does not even
tell me, what was wrong??
|
|
  |
|
|
<?php
function true_val() { return true; }
$x = true_val();
if (!empty($x)) echo "true1";
if (isset($x)) echo "true2";
?>
|
The workaround. Save your result in a temporary variable.
show me
|