|
Posted by Jochem Maas on 09/20/05 17:59
Michael Sims wrote:
> 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:
right so $a evaluates to 5 and a reference to the value of $a is passed. what you say doesn't make sense (to me)
take a look at the following:
<?
$b = 6;
$c = "another string";
var_dump(($a = 5), $a, ($a = "some string"), $a, ($a = $b), ($a = $c), $b, $c);
?>
as you see dumping the expression ($a = 5) and dumpimg plain old $a result in the same (as far as the output
is concerned) its therefore not possible to conclude that
>
> 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...
I don't think they are, and you're examples don't prove it.
Anyone care to come up with the proof. or explain to thick-eared old me
where I am mistaken.
>
[Back to original message]
|