Hello Stanislav,

Monday, January 5, 2009, 6:03:56 AM, you wrote:

> Hi!

>>   some time back (August 08) I complained about 'use' being at a weird
>> position and not at the same place as 'global' or 'static' where I
>> expected it. Back then Dmitry asked me to provide a patch to check out
>> the alternative. Now during the holidays I finally found some time to
>> change from:
>>        $f = function() use ($x) {}
>> to:
>>        $f = function() { use $x; }
>> 
>> Patch is attached.
>> 
>> Comments?

> I don't really see any "consistency" in it - this "use" syntax has 
> nothing to do with other "use" (namespace one) even if it looks almost 
> exactly like one in proposed patch. It also is subtly different from 
> global or static - different enough to make people think "ok, 'global' 
> is always by ref and 'use' looks like 'global' for consistency reasons - 
> does it mean it is consistently by-ref?" Not to mention questions like 
> "can I write 'use' in the middle of the code, since I can do it with 
> "consistent" constructs like 'static' or 'global'? What if I refer to 
> the variable before - will it be already bound?", etc. I think it would 
> not improve code readability and not really make it "consistent" anyway.

We have the same with global and static. Can you write them in the middle
of a funciton/method? So asking for what the consequence is, is irrelevant
unless you want to clean up that mess and correct the parser rules knowing
that it would break most PHP applications out there. Next, we chose 'use'
for the keyword, knowing that it was already used elsewhere, dciding that
it is the lesser evil opposed to creating yet another keyword with all
implications of that. So this part is irrelevant to my point as well.

What is left is moving something we decided upon so that it might look like
something that is similar already avoiding to create a pretty new syntax
that in my opinion is unnecessary different from anything we already have.

In fact 'use' means create a static variable from the surrounding context,
while 'static' means create a new static variable. Actually the executor
does not know the difference at all. Next 'global' means allow to use a
global variable.

So:
function () {
  global $foo;
  static $bar;
  use $baz;
}

Is pretty clear to me, as all three statements have a defined keyword. And
I would really prefer if all I have to teach is the meaning of the keyword.
And not having to teach a completely new syntax:

function() use($baz) {
  global $foo;
  static $bar;
}

That simply contradicts the KISS approach because it requires one
additional level of understanding.

And to answer the other question. Obviously 'sttaic' and 'use' are executed
at compile time, so whereever you place them, they are executed before
anything else. Thus it doesn't matter where you place them.

So here consistency means placing a syntactical element at the same
syntactical location related syntactical elements are placed.


Best regards,
 Marcus


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

Reply via email to