Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Extending classes multiple times

0 views
Skip to first unread message

Matt Friedman

unread,
Dec 6, 2001, 3:52:18 PM12/6/01
to php-g...@lists.php.net
I had been under the impression that one could extend a class only once.
That is, if I extend class A with class B I would then not be able to
extend B again with any other class.

See: http://www.php.net/manual/en/keyword.extends.php
"An extended class is always dependent on a single base class, that is,
multiple inheritance is not supported. Classes are extended using the
keyword 'extends'."

With some testing however, it appears that I can extend class B with
class C and class C with class D and so on...

Am I misinterpreting the manual? I suspect I am. Or is this a new
feature. Thoughts?

Thanks,

Matt Friedman
Web Applications Developer
www.SpryNewMedia.com
Email: ma...@SpryNewMedia.com

Rasmus Lerdorf

unread,
Dec 6, 2001, 2:51:33 PM12/6/01
to Matt Friedman, php-g...@lists.php.net
> I had been under the impression that one could extend a class only once.
> That is, if I extend class A with class B I would then not be able to
> extend B again with any other class.
>
> See: http://www.php.net/manual/en/keyword.extends.php
> "An extended class is always dependent on a single base class, that is,
> multiple inheritance is not supported. Classes are extended using the
> keyword 'extends'."
>
> With some testing however, it appears that I can extend class B with
> class C and class C with class D and so on...
>
> Am I misinterpreting the manual? I suspect I am. Or is this a new
> feature. Thoughts?

This is not a new feature. In your example each class only has a single
parent. Multiple Inheritance is when you do something like:

class C extends A,B { ... }

Doing B extends A followed by C extends B is still single inheritance.

-Rasmus

Matt Friedman

unread,
Dec 6, 2001, 4:04:52 PM12/6/01
to php-g...@lists.php.net
This is what I had thought. I wasn't sure and needed the clarification.

Thanks as always!

Matt Friedman


-----Original Message-----
From: Harshdeep S Jawanda [mailto:hs_ja...@yahoo.co.in]
Sent: Thursday December 6, 2001 1:55 PM
To: Matt Friedman
Cc: php-g...@lists.php.net
Subject: Re: [PHP] Extending classes multiple times

I am not very sure what your question is, but "multiple inheritance"
means that a derived class can inherit (i.e., be derived from) more
than one class.

In multiple inhericance, you can have:

A B
| |
+---+---+
|
C

Here, C is simultaneously derived from A & B. You can't have this in
single inheritance (which is what the PHP manual is saying). This means
that C can be derived from either A or B, not both.

The following is always possible, irrespective of whether multiple
inheritance is supported or not:

A
|
+-B
|
+-C
|
+-D

This is three different classes (B, C and D) derived from A.

Hope this helps clarify your doubts.

--- Matt Friedman <ma...@sprynewmedia.com> wrote:
> I had been under the impression that one could extend a class only
> once.
> That is, if I extend class A with class B I would then not be able to
> extend B again with any other class.
>
> See: http://www.php.net/manual/en/keyword.extends.php
> "An extended class is always dependent on a single base class, that
> is,
> multiple inheritance is not supported. Classes are extended using the
> keyword 'extends'."
>
> With some testing however, it appears that I can extend class B with
> class C and class C with class D and so on...
>
> Am I misinterpreting the manual? I suspect I am. Or is this a new
> feature. Thoughts?
>

> Thanks,
>
> Matt Friedman
> Web Applications Developer
> www.SpryNewMedia.com
> Email: ma...@SpryNewMedia.com
>
>
>
>
>

> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-general...@lists.php.net
> For additional commands, e-mail: php-gene...@lists.php.net
> To contact the list administrators, e-mail:
> php-lis...@lists.php.net
>
>
>


=====
Please send all emails to my automatically redirecting
address: hars...@graffiti.net

Regards,
Harshdeep S Jawanda
[hars...@graffiti.net]

__________________________________________________
Do You Yahoo!?
Send your FREE holiday greetings online!
http://greetings.yahoo.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: php-general...@lists.php.net
For additional commands, e-mail: php-gene...@lists.php.net
To contact the list administrators, e-mail: php-lis...@lists.php.net


Harshdeep S Jawanda

unread,
Dec 6, 2001, 2:55:28 PM12/6/01
to Matt Friedman, php-g...@lists.php.net
I am not very sure what your question is, but "multiple inheritance"
means that a derived class can inherit (i.e., be derived from) more
than one class.

In multiple inhericance, you can have:

A B
| |
+---+---+
|
C

Here, C is simultaneously derived from A & B. You can't have this in
single inheritance (which is what the PHP manual is saying). This means
that C can be derived from either A or B, not both.

The following is always possible, irrespective of whether multiple
inheritance is supported or not:

A
|
+-B
|
+-C
|
+-D

This is three different classes (B, C and D) derived from A.

Hope this helps clarify your doubts.

--- Matt Friedman <ma...@sprynewmedia.com> wrote:

0 new messages