Possible to define methods outside the class?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
gavagai
Forum Newbie
Posts: 2
Joined: Wed Jul 16, 2008 10:48 am

Possible to define methods outside the class?

Post by gavagai »

Hi,

Can anyone tell me if it's possible to define methods of a class outside the original class definition - specifically, in a seperate include file?

Thanks,

Tom
User avatar
dhrosti
Forum Commoner
Posts: 90
Joined: Wed Jan 10, 2007 5:01 am
Location: Leeds, UK

Re: Possible to define methods outside the class?

Post by dhrosti »

As far as I know its not possible.

What are you trying to achieve? there might be an alternative solution...
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: Possible to define methods outside the class?

Post by Benjamin »

Is this a homework or job interview question?
gavagai
Forum Newbie
Posts: 2
Joined: Wed Jul 16, 2008 10:48 am

Re: Possible to define methods outside the class?

Post by gavagai »

Well the aim is just to tidy up a big class and move deprecated methods into a seperate file
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: Possible to define methods outside the class?

Post by Benjamin »

You can extend existing classes quite easily.

http://php.benscom.com/manual/en/keyword.extends.php
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: Possible to define methods outside the class?

Post by Eran »

A better solution might be to use object composition. http://www.artima.com/lejava/articles/d ... ples4.html
Post Reply