-
Notifications
You must be signed in to change notification settings - Fork 7.7k
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] Implement final anonymous classes #11126
base: master
Are you sure you want to change the base?
Conversation
I would prefer them being made final by default, as I doubt many people are relying on this behavior. Either way, that needs some discussion on the ML. 🙂 |
100% agree, though this would probably require an RFC (?). Submitted this in the meantime as it doesn't involve breaking changes, will post something to the internals mailing list regarding this MR and other possible options :) |
As it might be a BC break I think an RFC would be a good idea |
@KapitanOczywisty Indeed. That's probably more of an oversight of the original RFC given that it doesn't talk about it at all. Both solutions are languages changes and as such need an RFC. |
@mvorisek Not really. The class needs to be named via class alias for this to work anyway, so why not just name the original class? (That does require eval though). |
@iluuu1994 proxy classes are generated like:
where I am pointing out that making anonymous class final implicitly would break ORMs which relies on it. |
@mvorisek Can you link something that uses this in the wild? That snippet doesn't make much sense, since |
Doctrine ORM uses that for example (for properties lazy-load, real properties are unset in construct) and anonymous class is allowed AFAK. |
But how would that work? First you need an instance of your anonymous class so that you can extract the class name, create a unique alias to it and pass the alias to the proxy factory. Furthermore, the anonymous class could not be autoloaded and so neither could the proxy class. That sounds dubious at best. |
here is example of proxied anonymous class: https://3v4l.org/NoPDi/rfc#vgit.master |
The question wasn't really whether it was possible, but whether it was useful. I don't see why anybody would write such code. |
But many ORM libs do so. They accept a class/instance, proxy it for lazy loading, and it should not matter if you pass standard or anonymous class to them, this is working now and as long as there is no substancial perfomance improvement (from better JITed code), it should be kept supported. |
Before merging this (if we do), I'd suggest forbidding using class_alias on such classes. |
@nicolas-grekas No worries, neither solution should just be merged. Given that this is a language change and there was some controversy an RFC is warranted.
Note that the main reason for this PR is to enable some additional optimizations for anonymous classes that are almost exclusively final, i.e. for final classes we know that no "dynamic dispatch" is possible, and so can rely on method signatures. I don't think having aliases to anonymous classes itself causes any issues. |
OK thanks. I'm making this proposal to forbid aliasing final anonymous classes so that they can truly be considered anonymous. Currently, you can give an addressable name to an anonymous class via aliasing, and that's a leak IMHO. While I don't think we can close it for existing anonymous classes, we could for final ones. |
Note that, even if we disallow |
e92e880
to
57f5db1
Compare
This should also allow some additional opcache optimizations.