| 
	
 | 
 Posted by ZeldorBlat on 11/06/07 20:06 
On Nov 6, 2:27 pm, Csaba Gabor <dans...@gmail.com> wrote: 
> In the following PHP code, the final printed line shows 'frob: 
> something'.  Why is it not 'frob: else'?  After all, if I replace the 
> first line with $frob = "something"; test ($frob); then the final 
> printed line does show 'frob: else' 
> 
> Csaba Gabor from Vienna 
> PHP 5.2.4 on WinXP Pro 
> 
> test ($frob = "something"); 
> print "frob: $frob <br>\n"; 
> 
> function test(&$val) { 
>   print "val pre: $val <br>\n"; 
>   $val = "else"; 
>   print "val post: $val <br>\n"; } 
 
It's because you're not really passing a variable -- you're passing 
the result of an expression.  If you enable E_STRICT you'll get the 
following: 
 
Strict Standards: Only variables should be passed by reference 
 
Since you haven't passed a variable, modifying the value inside the 
function is only modifying the local value.
 
  
Navigation:
[Reply to this message] 
 |