RE: [PHP] Tidying code for PHP5.0.5/PHP4.4.0
| From: | Michael Sims | Date: | Tue, 20 Sep 2005 14:11:08 +0000 |
| Subject: | RE: [PHP] Tidying code for PHP5.0.5/PHP4.4.0 | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-222777@lists.php.net to get a copy of this message | ||
Jochem Maas wrote:
>>> foo($a = 5);
>
> by definition the expression is evaluated _before_ the function is
> called - so the expression is not passed to the function, the result
> of the expression is passed ... I was under the impression that the
> the expression evaluates to a 'pointer' (I'm sure thats bad
> terminology) to $a ... which can taken by reference by the function.
>
> possibly I am completely misunderstanding what goes on here.
When used as an expression, an assignment evaluates to whatever is on the right side of the
assignment operator, not the left. Example:
var_dump($a = 5);
outputs
int(5)
var_dump($a = "some string");
outputs
string(11) "some string"
So, as far as foo() knows:
foo($a = 5);
and
foo(5);
are exactly the same...