Why isn't base class constructors or destructors required to be called?

php.internals

Terje Slettebø

19 years ago
Hi all. Another issue. :) As usual, I searched the archive first, but found only a few postings from 2004 on the subject, without much clarification, so I'd like to pose the question again. If this has been discussed, I'd welcome hearing what was the outcome of it. In PHP, unlike other languages with support for OO (such as C++ and Java), base class constructors are not automatically called (or enforced being called). I wonder why this is so? If the answer is "flexibility", has the issues arising from this been seriously considered...? This means that if I make a base class "Base", which needs to have its constructor and/or destructor called, to be initialised properly, there's currently _no way_ to enforce that, in PHP (that I know of). This means you risk half-constructed and half-destructed objects around, and in that case, program correctness is compromised. Regards, Terje

Johannes Schlueter

19 years ago
Hi Terje, you should look harder: http://www.php.net/~derick/meeting-notes.html#function-require-construct-to-force-calling-the-parent-s-constructor ;-) johannes Terje Slettebø wrote:

Terje Slettebø

19 years ago
Hi Johannes.
> you should look harder: >
http://www.php.net/~derick/meeting-notes.html#function-require-construct-to-force-calling-the-parent-s-constructor Thanks for your reply, but I've actually seen that one. However, no _reason_ for not allowing/requiring this in "userland" is given. Only the conclusions: "Conclusions: - We add a flag to the class structure to record this - We do not add new syntax for this to userland" Reading this again, I'm wondering if I interpret it right in that there will be no way to enforce this in PHP code? If so, why not? Regards, Terje
> Terje Slettebø wrote: > > Hi all. > > > > Another issue. :) As usual, I searched the archive first, but found only
a
> > few postings from 2004 on the subject, without much clarification, so
I'd
> > like to pose the question again. If this has been discussed, I'd welcome > > hearing what was the outcome of it. > > > > In PHP, unlike other languages with support for OO (such as C++ and
Java),
> > base class constructors are not automatically called (or enforced being > > called). I wonder why this is so? If the answer is "flexibility", has
the
> > issues arising from this been seriously considered...? > > > > This means that if I make a base class "Base", which needs to have its > > constructor and/or destructor called, to be initialised properly,
there's
> > currently _no way_ to enforce that, in PHP (that I know of). This means
you
> > risk half-constructed and half-destructed objects around, and in that
case,