On 15 March 2023 03:28:39 GMT, "Alexandru Pătrănescu" <dreal...@gmail.com> 
wrote:

>How about first implementing use() for anonymous classes first?
>Something like:
>
>function foo(int $outer) {
>     return new class() use($outer) {
>         public function getIt() {
>             return $outer;
>         }
>     };
>}


I think it's a lot less clear exactly where the variable is being imported to 
that way. Would you still be able to overwrite $outer as a normal local 
variable in that function scope? Would it return to its captured value every 
time the function runs? It's different from capturing into a function, because 
you're not just adding a variable to a single existing scope.

Just allowing the captured var for property initialisation would be less 
ambiguous, but having to list it in use() and then in the property list would 
be the same amount of code as you can currently get to with constructor 
promotion (see my first example in the thread).

From what Ilija has pointed out, the implementation of actually getting the 
values into the right place is going to be harder than handling the syntax 
anyway. My current feeling is that if it's possible at all, it will end up as a 
shorthand for that constructor example: declaring normal properties, and 
populating them as the instance is initialised.

Regards,

-- 
Rowan Tommins
[IMSoP]

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

Reply via email to