gthelp.com

Domain for sale - best offer

Welcome Guest, our newest member is: maxxxmodels2009  
User Name Password Save?
 PHP 5/OOP, Functionality similar to an Abstract method?

Post New Content Post New Content  

Default 

PHP 5/OOP, Functionality similar to an Abstract method?

  #1  
Old June 12th, 2004, 08:16 AM
Guest
 
Posts: n/a

I have an abstract class with quite a few 'children'. Essentially I want
to be able to interchange calls between children (Take a script, written
with ClassA and redefine the variable as ClassB etc.)

Though there is a large subset of methods all of these children declare,
there are a few which only *some* declare. What I think I'm looking for
is a variation on an abstract method that, if not defined in a child,
will do nothing. Using an abstract method forces me to declare the
method in the child with an empty body.

Are you understanding me?

Any thoughts on the matter would be appreciated.

Thanks,
Chris



Default 

Re: PHP 5/OOP, Functionality similar to an Abstract method?

  #2  
Old June 12th, 2004, 03:06 PM
Guest
 
Posts: n/a

Chris wrote:

> I have an abstract class with quite a few 'children'. Essentially I want
> to be able to interchange calls between children (Take a script, written
> with ClassA and redefine the variable as ClassB etc.)
>
> Though there is a large subset of methods all of these children declare,
> there are a few which only *some* declare. What I think I'm looking for
> is a variation on an abstract method that, if not defined in a child,
> will do nothing. Using an abstract method forces me to declare the
> method in the child with an empty body.
>


AFAIK, there is no support for this explicitly in PHP5. You would have
to implement something yourself, like putting a die() or exit in the
abstract method in the parent class.

If you just want an empty funciton anyway, why don't you just put an
empty function in the parent? I don't see why you would need PHP to yell
at you when you don't want to do antyhing with it anyway.

--
paperCrane <Justin Patrin>



Default 

Re: [PHP] Re: PHP 5/OOP, Functionality similar to an Abstract method?

  #3  
Old June 12th, 2004, 04:08 PM
Guest
 
Posts: n/a

Justin Patrin wrote:

> Chris wrote:
>
>> I have an abstract class with quite a few 'children'. Essentially I
>> want to be able to interchange calls between children (Take a script,
>> written with ClassA and redefine the variable as ClassB etc.)
>>
>> Though there is a large subset of methods all of these children
>> declare, there are a few which only *some* declare. What I think I'm
>> looking for is a variation on an abstract method that, if not defined
>> in a child, will do nothing. Using an abstract method forces me to
>> declare the method in the child with an empty body.
>>

>
> AFAIK, there is no support for this explicitly in PHP5. You would have
> to implement something yourself, like putting a die() or exit in the
> abstract method in the parent class.
>
> If you just want an empty funciton anyway, why don't you just put an
> empty function in the parent? I don't see why you would need PHP to
> yell at you when you don't want to do antyhing with it anyway.
>

When I said "will do nothing" I was meaning the method call, not the
entire script. I can't put anything into an abstract method, it only
defines the method name and argument list, a body is nto allowed in an
abstract method.

Upon further reflection it appears that the abstract method is what I
really want. I'll just have to implement an empty body.

Thanks


 

Post New Content Post New Content  

Display Modes


Staff - Contact Us - Main - Archive - Technorati Profile - Top  
vBulletin Software: Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Page generated in 0.07631 seconds with 10 queries