-
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
Engine calls to private destructors cause errors #16077
Comments
But what's the right behavior? The other warnings indicate that the magic methods aren't really intended to be non-public. For Let's wait for others to chime in. |
That's what I thought too until __adrian on libera.chat#php pointed out you can actually call all of the magic methods manually: I'd agree that users probably shouldn't be able to call magic methods directly but at this point that would introduce a lot of BC breaks |
That's what I referred to here:
I.e. it is not possible to prevent the user from calling Edit: Sorry for quoting the same test. My brain auto-skipped the quote. 😄 |
Ah, I misread you sorry.
On the contrary. In the case of A quick symbol search shows me a lot of libraries that have had to add error checking (or silencing) in destructors that they wouldn't have had to if they could declare it private or protected without causing errors. In the few cases where you actually want to reuse the destructor functionality from outside you can always just make a public method and call it from inside The reason Contrast that with stuff like Anyway, I didn't plan on making this a big discussion about magic method visibility, I just thought it was obvious that the engine should be able to call a private
|
Right. My point was that In any case, since this is a behavioral change, it would make sense to discuss this on the mailing list. If that's something you'd like to kick off, please send a mail to the internals mailing list. |
I don't think it's necessary to change the way If you just let the engine call destructors regardless of visibility, that brings behavior in line with documentation (And the clear intent since there's no warning on private destructor declaration) and doesn't break BC. (Unless someone relied on private destructors crashing the application in lieu of But OK, I'll send a mail and ask for feedback there |
It seems there is a possibility to need the current behaviour; although likely not particularly used as such:
|
Well it doesn't magically come back in scope somehow so it's just leaking whatever the destructor was there to clean up. Since the destructor is always executed by the engine in global scope (apparently) there's no situation where it wouldn't throw -- you'd be just as well off not having a destructor at all and going straight to the catch code
That only works if that variable's the last reference to the object. Remember that objects are always by reference: https://3v4l.org/K5ErQ
Basically PHP has COW objects as well as COW strings |
Description
https://3v4l.org/bKijA
While private magic method declarations result in a visibility warning, they still work when invoked by the engine as in the cases of
__debugInfo
(and__sleep
since 8.1)Private destructors however cause errors whenever an instance goes out of scope. The engine should always be able to invoke a destructor when destroying an instance.
PHP Version
8.4
Operating System
No response
The text was updated successfully, but these errors were encountered: