Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RFC: Anonymous Class Lexical Scope #1874

Closed
wants to merge 2 commits into from
Closed

RFC: Anonymous Class Lexical Scope #1874

wants to merge 2 commits into from

Conversation

krakjoe
Copy link
Member

@krakjoe krakjoe commented Apr 20, 2016

RFC

Rewritten patch, so that it actually makes some sense.


EG(scope) = Z_OBJCE_P(object);

val_ptr = Z_OBJ_HT_P(object)->get_property_ptr_ptr(object, &name, type, NULL);
Copy link
Member Author

@krakjoe krakjoe Apr 20, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm pretty sure that this can never return anything other than a valid container now, since properties are always declared.

@Majkl578
Copy link
Contributor

Majkl578 commented May 1, 2016

Hello, how about the comments from former PR #1871? Have you considered those suggestions?

@krakjoe
Copy link
Member Author

krakjoe commented May 2, 2016

The technical issues have been mostly addressed, the patch is still pending final review, so may have missed something nikita said.

new class use ($foo->bar as private $bar)

I have considered it, since there is already a way for you to change the default private visibility to something else, that part of the idea isn't necessary.

I'm not totally convinced of the utility of being able to change the properties name, I can't think of a scenario where it would be required; You should normally write use() before you write the class, I would suppose.

new class use ($this as private $outsideScope)

use($this) is missing, but it's also missing from anonymous functions. I tend to think that it may be better to leave this alone for now, come up with a solution that is acceptable for anonymous functions and try to use as close to the same syntax/rules as possible for anonymous classes.

Another possible solution is that it may not be necessary to give $this another name, it may be possible to bind the anonymous class to it's super class and just use($this), so that $this in the anonymous class and it's super class are the the same.

Another possible solution is the ability to rebind an anonymous class at runtime, just as closures are able to be rebound.

The use of $this doesn't feel like a problem we ought to try and [only] solve here.

Edit: I quite like the idea of use($this as $thing) for both anonymous classes and functions, I may attempt to do that for both and RFC it, although it's too late for 7.1 now.

@nikic nikic added the RFC label Jul 10, 2016
@php-pulls
Copy link

Comment on behalf of kalle at php.net:

Closing due to no activity, please re-open if you still intend on working on it

@php-pulls php-pulls closed this Nov 21, 2018
@Hbm134
Copy link

Hbm134 commented Dec 12, 2024

That was awesome (info) mark and write down (done)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants