Re: In what scenario an extension of a class is useful?

From: Date: Tue, 29 Jun 2010 20:26:50 +0000
Subject: Re: In what scenario an extension of a class is useful?
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-306543@lists.php.net to get a copy of this message
On Wed, Jun 23, 2010 at 02:58, Rene Veerman <rene7705@gmail.com> wrote: > inheritance of this kind is useful if you have common descendants for > specific types of object > Nice thought. I imagine something like a DB wrapper, and implementing things such as multiqueries and others on an extension based on the basic connection made in the "original" class. Am I right on that? > another use, is a modification of a certain component. > descend it from the parent object and override the functions. > you can do pre processing and post processing by overriding functions. > So, you're saying I can do something like this? : class foo { function hello($a = '') { echo 'hello '.$a; } } class bar extends foo { function hello($a = '') { if (!empty($a)) parent::hello($a); else echo 'bye world'; } } $xx = new bar(); $xx->hello('asdf'); $xx->hello(); Which will print (hopefully, haven't test it yet): hello asdf bye world That would be really a nice way of updating certain vital apps, without breaking basic functionality. Thanks for your answer :) Greetings !! -- Mailed by: UnReAl4U - unreal4u ICQ #: 54472056 www1: http://www.chw.net/ www2: http://unreal4u.com/

« previous php.general (#306543) next »