Re: Protected destructors

From: Date: Sat, 28 Sep 2024 17:23:35 +0000
Subject: Re: Protected destructors
References: 1 2 3 4  Groups: php.internals 
Request: Send a blank email to internals+get-125703@lists.php.net to get a copy of this message
Okay. My point is that you cannot know (unless there are no circular dependencies) *when* a destructor is called by the engine;
The benefit of non-public visibility isn't when it's called, but how many times it's called. If you can declare your destructor non-public you can be confident it'll only be called once per instance (By the engine) Or is there a scenario where the engine will call a destructor more than once on the same instance?
Destructors should (IMHO) be public. Not necessarily because they can be called, but classes with destructors hint at underlying behavior when destructed. For performance, you might want to defer that by retaining a reference. If a class has a hidden destructor, you have to go read the code to find it.
Wouldn't you have to read the code to see if it had a public destructor too?

« previous php.internals (#125703) next »