Inheritance
Posted: Sat Jun 07, 2003 3:12 pm
Manual says php does not support multiple inheritance - each child can only have a single base class.
However, when I tried some tests, I found that with:
parent class A --> child B extends A --> child C extends B
.. child C CAN access the methods and properties of A
I guess they mean that you can't have several parents and one child which extends them all.
Anyway, I seem to have discovered that you can (apparently) build "trees" of classes - similar to the filesystem directory tree. I'm looking at using this ability to share out common code efficiently between a bunch of related tasks - for example file writing / folder browsing / ftp.
There would be a single base class with methods common to all branches, maybe an intermediate layer with stuff common to a particular branch, and then a final layer which by now is getting much less abstract: ie childs which draw particular pages for a specific site.
Re-coding the program for a new site would simply mean re-coding the top-level childs.
So, my question is have I got all that right? Before I start re-working thousands of lines of code it would be nice to know that the principle is sound.
This seemed more at home here - but stick it in the normal forum if you think it's more a of a basic query.
However, when I tried some tests, I found that with:
parent class A --> child B extends A --> child C extends B
.. child C CAN access the methods and properties of A
I guess they mean that you can't have several parents and one child which extends them all.
Anyway, I seem to have discovered that you can (apparently) build "trees" of classes - similar to the filesystem directory tree. I'm looking at using this ability to share out common code efficiently between a bunch of related tasks - for example file writing / folder browsing / ftp.
There would be a single base class with methods common to all branches, maybe an intermediate layer with stuff common to a particular branch, and then a final layer which by now is getting much less abstract: ie childs which draw particular pages for a specific site.
Re-coding the program for a new site would simply mean re-coding the top-level childs.
So, my question is have I got all that right? Before I start re-working thousands of lines of code it would be nice to know that the principle is sound.
This seemed more at home here - but stick it in the normal forum if you think it's more a of a basic query.