Why isn't base class constructors or destructors required to be called?
| From: | Terje Slettebø | Date: | Thu, 14 Sep 2006 18:03:52 +0000 |
| Subject: | Why isn't base class constructors or destructors required to be called? | ||
| Groups: | php.internals | ||
| Request: | Send a blank email to internals+get-25693@lists.php.net to get a copy of this message | ||
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