One important thing I'd like to have here is importing the "outer" $this.
e.g.:
public function bar(){
return new class use($this as $that){
public function test(){
return $this->that;
}
};
}
And I dislike how this would look with NikiC's proposal:
return new class{
private $that = $this;
};
Especially because "constant expressions" could change in the future and
allow operations with $this, eg:
An option could be what Joe proposed `new class use($this as $that)` (which
I would particularly like if it allowed any kind of expression `new class
use($this->foo->baz() + 10 as $that){}`)
Or introduce a scope resolution keyword that works similarly to `parent::`.
E.g.:
public function bar(){
$foo = $this->getFoo();
return new class{
private $that = outer::$this;
private $foo = outer::$foo;
private $fooCall = outer::$this->getFoo();
};
}
Thoughts?
2016-05-01 16:30 GMT+02:00 Björn Larsson <[email protected]>:
> Hi,
>
> Nice and clear-cut RFC! One reflection is if the usage of use
> to "import" variables could have an impact on a proposal
> for a short form of Lambda functions in the future?
>
> Cheers //Björn
>
> PS I liked the Short Closure RFC btw.
>
>
> Den 2016-04-26 kl. 10:25, skrev Joe Watkins:
>
>> Morning internals,
>>
>> Just to be clear, the implementation is now in good shape, the
>> discussion may continue.
>>
>> Attached is message from a confused contributor ... sorry about the
>> confusion :)
>>
>> Cheers
>> Joe
>>
>> ---------- Forwarded message ----------
>> From: Yasuo Ohgaki <[email protected]>
>> Date: Tue, Apr 26, 2016 at 9:13 AM
>> Subject: Re: [PHP-DEV] RFC: Anonymous Class Lexical Scope
>> To: Joe Watkins <[email protected]>
>>
>>
>> Hi Joe,
>>
>> Since you seem to pause this RFC activity for now, I'm sending this
>> mail only to you.
>>
>> On Wed, Apr 20, 2016 at 3:01 PM, Joe Watkins <[email protected]>
>> wrote:
>>
>>> I must say that of all the suggestions made so far for syntax, I still
>>> prefer use().
>>>
>> I strongly support "use()".
>> It's the way PHP imports other scope variables :)
>>
>> Regards,
>>
>> --
>> Yasuo Ohgaki
>> [email protected]
>>
>>
>
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>