Re: Calling parent's constructor
| From: | Kristian Köhntopp | Date: | Thu, 14 Dec 2000 13:39:13 +0000 |
| Subject: | Re: Calling parent's constructor | ||
| References: | 1 2 3 4 5 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-41355@lists.php.net to get a copy of this message | ||
Zeev Suraski wrote:
> >Inherited constructors are already broken in Zend, and cannot
> >be fixed any more.
>
> Christ.
"Kris", with a K. And no, I did not choose that name. :-)
> I *love* it when you state opinions as axioms. But let's
> agree to disagree.
Actually, we agree, at least on the "cannot be fixed" part.
Unless you want to give constructors a fixed name, such as
__init(). This would greatly simplify inheritance rules and
the whole parent::-matter, but it would also break about all
existing OO code.
Using a fixed name, you do not need three rules to desribe
how constructors work (currently we have: 1. constructors are
named like their class, 2. constructors are never inherited
functions, 3. derived classes without constructors call their
superclass constructor, if there is one, in contradiction to
rule 1, but for the greater benefit of the OO framework :-).
Instead you just need a single rule (1. constructors are
named __init(), they are inherited unless overwritten by the
derived class).
As an added benefit, in the "fixed constructor name" model,
you'd not need __parent() at all, parent::__init() would
easily suffice.
I happen to think that the current constructor logic is
broken, if you count unnecessary convolution as a bug
(We had a single rule when we started, 1. constructors
are named like their class). Adding features to it only makes
it more ugly, like the two additional inheritance-of-
constructors rules, and now the ::__parent() pseudo-function,
which actually _is_ a fixed constructor name in disguise (it
is just named __parent() instead of __init()).
> > This looks sensible. I suggest parent::__parent(),
> >though, to go along with __wakeup(), __sleep(), and __delegate().
>
> At the risk of giving a few people heart attacks from surprise, I'll agree
> with you here. That's the solution I thought about for this issue as well.
Another approach to the problem (just in case you count agreeing
with me as a bug, I'm going to offer another alternative that is
harder for you to agree on with me :-) would be to change to fixed
constructor names (1. constructors are called __init()), AND
keep the variable constructor names logic for compatibility.
That would fix the core of the problem without killing all the
existing code. And it would bring beauty back to PHP OO.
Kristian
--
Kristian Köhntopp, NetUSE AG Siemenswall, D-24107 Kiel
Tel: +49 431 386 436 00, Fax: +49 431 386 435 99
Using PHP3? See our web development library at http://phplib.netuse.de/