473,466 Members | 1,381 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

PHP5 and Classes

My OOP knowledge is flaky, at best, so please be patient with me :-)

I've downloaded the FPDF class from www.fpdf.org as well as some of
the scripts that are available.

Each of these scripts use:
class mine extends FPDF {}
which is what you'd expect when extending out to a new class.

What I want/would like to do is to include multiple scripts which
extend the base class of FPDF. I've managed to daisy-chain these
classes similar to:
-------------------------------------------------------------------------
<?php
class FPDF {
function FPDF(){ echo "class FPDF<BR>";}
function setSize(){ echo "setSize_FPDF()<BR>";}
}
class B extends FPDF {
function B(){ echo "class B<BR>";}
function setSize(){ echo "setSize_B()<BR>......";parent::setSize();}
}
class C extends B {
function C(){ echo "class C<BR>";}
function setLimit(){ echo "setLimit_C()<BR>";}
}
class D extends C {
function D(){ echo "class D<BR>";}
function PrintLine(){ echo "PrintLine_D()<BR>";}
}
class me extends D {
function me(){ echo "class me<BR>";}
function setSize()
{
echo "setSize_E()<BR>&nbsp;&nbsp;&nbsp;";
//--- this only gets the class B function
parent::setSize();
}
}
//--- test code
$x = new me();
$x->FPDF();
$x->PrintLine();
$x->setSize();

/* --- output
class me
class FPDF
PrintLine_D()
setSize_E()
setSize_B()
setSize_FPDF()
*/
?>
-------------------------------------------------------------------------
Now even *I* know that OOP was never intended to be like this. Is
there a better/correct way?

In my code how would I reference the FPDF setSize() method?
FYI: the setSize is not overriding the base class, it is an internal
function to that class only.
---------------------------------------------------------------
jn******@yourpantsyahoo.com.au : Remove your pants to reply
---------------------------------------------------------------
Jul 12 '06 #1
5 1494
Jeff North wrote:
My OOP knowledge is flaky, at best, so please be patient with me :-)

I've downloaded the FPDF class from www.fpdf.org as well as some of
the scripts that are available.

Each of these scripts use:
class mine extends FPDF {}
which is what you'd expect when extending out to a new class.

What I want/would like to do is to include multiple scripts which
extend the base class of FPDF. I've managed to daisy-chain these
classes similar to:
-------------------------------------------------------------------------
<?php
class FPDF {
function FPDF(){ echo "class FPDF<BR>";}
function setSize(){ echo "setSize_FPDF()<BR>";}
}
class B extends FPDF {
function B(){ echo "class B<BR>";}
function setSize(){ echo "setSize_B()<BR>......";parent::setSize();}
}
class C extends B {
function C(){ echo "class C<BR>";}
function setLimit(){ echo "setLimit_C()<BR>";}
}
class D extends C {
function D(){ echo "class D<BR>";}
function PrintLine(){ echo "PrintLine_D()<BR>";}
}
class me extends D {
function me(){ echo "class me<BR>";}
function setSize()
{
echo "setSize_E()<BR>&nbsp;&nbsp;&nbsp;";
//--- this only gets the class B function
parent::setSize();
}
}
//--- test code
$x = new me();
$x->FPDF();
$x->PrintLine();
$x->setSize();

/* --- output
class me
class FPDF
PrintLine_D()
setSize_E()
setSize_B()
setSize_FPDF()
*/
?>
-------------------------------------------------------------------------
Now even *I* know that OOP was never intended to be like this. Is
there a better/correct way?

In my code how would I reference the FPDF setSize() method?
FYI: the setSize is not overriding the base class, it is an internal
function to that class only.
---------------------------------------------------------------
jn******@yourpantsyahoo.com.au : Remove your pants to reply
---------------------------------------------------------------
Jeff,

The quick answer is - you don't, at least directly.

In OO, inheritance is "hidden" - the fact you are using it is not known
to the code accessing the class, nor should it care. The interface to
your "me" class is the public functions in "me", plus all the public
functions in it's base class "D" (which, in turn, has an interface which
includes the public functions in "C", etc.). But your code really
doesn't know about "D", "C", etc. - OO has abstracted that for you.

You're overriding of setSize is correct. "me" should do its work, then
call its base class's setSize (or call then do its work), etc. That way
each class operates on its own data, and calls its base class to work on
further data. This allows you to change your class hierarchy with
(almost) complete freedom without having to change the program. For
instance, you could compress everything into a single class "me" - and
your program would still work.

Now - you want to just call setSize in class FPDF. OO doesn't allow
this because abstraction says class "FPDF" doesn't actually exist (the
*function* FPDF may just be a function in class "me" for all it cares).

So you can't do it directly. However, you *could* create a function in
FPDF with another name (i.e. setSizeFPDF) to do the same work. This
will add the new function to your public interface and you can call it
by itself.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jul 12 '06 #2
On Wed, 12 Jul 2006 10:30:05 -0400, in comp.lang.php Jerry Stuckle
<js*******@attglobal.net>
<M6******************************@comcast.comwrote :
>| Jeff North wrote:
| My OOP knowledge is flaky, at best, so please be patient with me :-)
| >
| I've downloaded the FPDF class from www.fpdf.org as well as some of
| the scripts that are available.
| >
| Each of these scripts use:
| class mine extends FPDF {}
| which is what you'd expect when extending out to a new class.
| >
| What I want/would like to do is to include multiple scripts which
| extend the base class of FPDF. I've managed to daisy-chain these
| classes similar to:
| -------------------------------------------------------------------------
[snip example code]
>| -------------------------------------------------------------------------
| Now even *I* know that OOP was never intended to be like this. Is
| there a better/correct way?
| >
| In my code how would I reference the FPDF setSize() method?
| FYI: the setSize is not overriding the base class, it is an internal
| function to that class only.
|
| Jeff,
|
| The quick answer is
It was quick - I only posted this about 20min ago :-)
>| - you don't, at least directly.
|
| In OO, inheritance is "hidden" - the fact you are using it is not known
| to the code accessing the class, nor should it care. The interface to
| your "me" class is the public functions in "me", plus all the public
| functions in it's base class "D" (which, in turn, has an interface which
| includes the public functions in "C", etc.). But your code really
| doesn't know about "D", "C", etc. - OO has abstracted that for you.
That makes sense :-)
I've never seen any example daisy-chain classes before.
>| You're overriding of setSize is correct. "me" should do its work, then
| call its base class's setSize (or call then do its work), etc. That way
| each class operates on its own data, and calls its base class to work on
| further data. This allows you to change your class hierarchy with
| (almost) complete freedom without having to change the program. For
| instance, you could compress everything into a single class "me" - and
| your program would still work.
Just as I thought. I need to go into each of these script files and
alter the function names so that they are not overriding each other.
>| Now - you want to just call setSize in class FPDF. OO doesn't allow
| this because abstraction says class "FPDF" doesn't actually exist (the
| *function* FPDF may just be a function in class "me" for all it cares).
|
| So you can't do it directly. However, you *could* create a function in
| FPDF with another name (i.e. setSizeFPDF) to do the same work. This
| will add the new function to your public interface and you can call it
| by itself.
Many thanks for your help.
---------------------------------------------------------------
jn******@yourpantsyahoo.com.au : Remove your pants to reply
---------------------------------------------------------------
Jul 12 '06 #3

I don't quite get what you're trying to accomplish (but I'm not that
bright).

You should avoid deep inheritance heirarchies.

Or perhaps you shouldn't override the methods in this manner, since you
are trying to achieve the ability to 'reach back' up the inheritance
chain to call the 'Grandparent' method.

Not sure if this helps.

Cheers,
Yong

Jeff North wrote:
My OOP knowledge is flaky, at best, so please be patient with me :-)

I've downloaded the FPDF class from www.fpdf.org as well as some of
the scripts that are available.

Each of these scripts use:
class mine extends FPDF {}
which is what you'd expect when extending out to a new class.

What I want/would like to do is to include multiple scripts which
extend the base class of FPDF. I've managed to daisy-chain these
classes similar to:
-------------------------------------------------------------------------
<?php
class FPDF {
function FPDF(){ echo "class FPDF<BR>";}
function setSize(){ echo "setSize_FPDF()<BR>";}
}
class B extends FPDF {
function B(){ echo "class B<BR>";}
function setSize(){ echo "setSize_B()<BR>......";parent::setSize();}
}
class C extends B {
function C(){ echo "class C<BR>";}
function setLimit(){ echo "setLimit_C()<BR>";}
}
class D extends C {
function D(){ echo "class D<BR>";}
function PrintLine(){ echo "PrintLine_D()<BR>";}
}
class me extends D {
function me(){ echo "class me<BR>";}
function setSize()
{
echo "setSize_E()<BR>&nbsp;&nbsp;&nbsp;";
//--- this only gets the class B function
parent::setSize();
}
}
//--- test code
$x = new me();
$x->FPDF();
$x->PrintLine();
$x->setSize();

/* --- output
class me
class FPDF
PrintLine_D()
setSize_E()
setSize_B()
setSize_FPDF()
*/
?>
-------------------------------------------------------------------------
Now even *I* know that OOP was never intended to be like this. Is
there a better/correct way?

In my code how would I reference the FPDF setSize() method?
FYI: the setSize is not overriding the base class, it is an internal
function to that class only.
---------------------------------------------------------------
jn******@yourpantsyahoo.com.au : Remove your pants to reply
---------------------------------------------------------------
Jul 12 '06 #4
ybakos wrote:
I don't quite get what you're trying to accomplish (but I'm not that
bright).

You should avoid deep inheritance heirarchies.

Or perhaps you shouldn't override the methods in this manner, since you
are trying to achieve the ability to 'reach back' up the inheritance
chain to call the 'Grandparent' method.

Not sure if this helps.

Cheers,
Yong

Jeff North wrote:

Actually, Yong, I find "deep inheritance hierarchies" to be useful at
times. Of course they've been complicated - but each class only needs
to worry about its own implementation and the interface of its base
class. It all depends on what you need.

As for overriding the functions - that's one of the beauties of OO
programming. You call setSize() in the lowest class, and it processes
the request and passes it on to the parent. Of course, each setSize()
should have the same purpose - just each one performs whatever work is
needed on its own class.

P.S. Please don't top post. This group uses bottom posting as a
standard. Thanks.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jul 12 '06 #5
On 12 Jul 2006 08:52:06 -0700, in comp.lang.php "ybakos"
<sp**@humanoriented.com>
<11*********************@s13g2000cwa.googlegroups. comwrote:
>| I don't quite get what you're trying to accomplish (but I'm not that
| bright).
|
| You should avoid deep inheritance heirarchies.
|
| Or perhaps you shouldn't override the methods in this manner, since you
| are trying to achieve the ability to 'reach back' up the inheritance
| chain to call the 'Grandparent' method.
That's the whole problem, I do not want to override the base class.
Each of these 'add-ons' have used the same function/method name in
several places.
>| Not sure if this helps.
|
| Cheers,
| Yong
---------------------------------------------------------------
jn******@yourpantsyahoo.com.au : Remove your pants to reply
---------------------------------------------------------------
Jul 13 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Philipp Lenssen | last post by:
I noticed there's an error in PHP when it receives form data. It seems to precede various characters with "\". I was wondering if that's about to get fixed in PHP5, or already is fixed in PHP4? (Or...
5
by: somaBoy MX | last post by:
I'm planning on installing the PHP5 RC1 on my local machine as a testing server. Are there any particulars I should be aware of for all my PHP4-developed applications to keep working? Or should the...
1
by: Matthew Bates | last post by:
Hi, I would like to use PHP5 to interact with an XML-RPC web service. I've noticed a number of libraries on the net however many are out of date and not specific to PHP5. Could anybody...
7
by: Rob Long | last post by:
Hey I've noticed a somewhat annoying feature in PHP5 when it comes to extended classes and types. If I declare an interface and a class that implements it, I get a "compile" error (read parse...
3
by: Philipp Lenssen | last post by:
I want to try the new Yahoo API, but I get the PHP5 error message Unknown encoding "utf-8" in the marked line below... (After that, applying the Xpath will fail as symptom of the first bug.) ...
12
by: Daedalus.OS | last post by:
Ok first I'm pretty new to OOP, so my question may sound stupid to some of you. If the only answer you can provide is "get a book about OOP" then don't loose your time and mine cause it's already...
2
by: Markus Ernst | last post by:
Hi In my application I have lots of require statements that include files residing in the same directory: index.php requires: require_once($_SERVER."/modules/cms/classes/page.php"); ...
0
by: dex | last post by:
Hi, I'm trying use a webservice with PHP5 soap extension in WSDL mode. I generated the php classes using wsdl2php. The problem is that 'auth' member of loginRequest (witch is a complex type)...
6
by: n8agrin | last post by:
I've been doing some level of PHP programming for many years now, and have in the past few months started implementing lots of the core PHP5 features into a new project, when I noticed some...
13
by: DigitalDave | last post by:
A project I did awhile back stored php5 objects in elements of the $_SESSION array between pages that were navigated on the site. There were object classes representing teachers, and object classes...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.