On Sunday 04 January 2009 8:17:27 pm Marcus Boerger wrote:
> Hello Larry,

> >
> > $f = function() use ($y, &$z) {
> >   global $x;  // By reference
> > }
> >
> > $y is clearly by value, and $z clearly by reference, as that parallels
> > the way function parameters work right next to the lexical variables.
> >
> > The way to increase consistency would be to allow the opposite:
>
> And then what do we do with static? And besides how is:
> ...use (&$ref)
> different from:
> ...use &$ref;

I don't recall if statics were discussed previously, but the concept of a by-
value static doesn't really make sense whereas it can for lexical or global 
variables.  

And the difference between use(&$var) and use &$var is that the latter looks 
like it SHOULD behave like the existing global keyword does, but can't because 
we need to support both by-value and by-reference.  (Honestly I'm more likely 
to use by-value myself, I think.)  So you'd have "global $foo" which is by-ref 
but "use $foo" which is by-value.  That's not at all consistent or intuitive.  
Putting it in the function signature means it behaves exactly like the rest of 
the function signature with regards to by-value vs. by-reference behavior.

> But maybe you want consistency by breaking nearly every PHP script ever
> written? Or did I miss some Months and it is early April rather than early
> January?

Neither.  At no point did I suggest removing the existing global keyword or 
altering its behavior.  I simply said that if we're concerned about lexical 
variables having one syntax and global variables a different syntax right now, 
the solution is to allow global variables to use the same syntax as lexical 
(in addition to the current mechanism) not to make lexical use the same syntax 
as global (which is not flexible enough to handle the use cases lexical 
variables need in a consistent fashion).  

No, I didn't explicitly say to keep the existing syntax as well; I figured it 
was implicit.  If that didn't make it through, I apologize.

-- 
Larry Garfield
la...@garfieldtech.com

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to