Jump to content

class or function?


maddogandnoriko

Recommended Posts

I have just recently begun oop programming with php. I am going to write a link verifer for my site that will go through many links and make sure they are valid. My question is....is this better suited for a class or function? For the sake of argument the link list will vary from just one links to many hundreds....

 

All help is appreciated,

                                Todd

 

 

Link to comment
https://forums.phpfreaks.com/topic/148007-class-or-function/
Share on other sites

a function is generally supposed to perform one action. If you have to do multiple actions on a common data set, then classes are prepared.

 

For example:

 

If you have a string and u just have to parse URLs from it, use function.

 

If you have a string and u have to parse URLs, process them, and store statistics in database then write a class which will have function for each action you want to do..

 

on broader level...

 

function is a piece of code performing an action , which can be reused.

 

Class generally represents an entity. It is a container for properties (member variables) and functions that can be performed on the entity.

 

there is no restriction as such for when u define a function and when u use a class, it depends on your choice :)...

Link to comment
https://forums.phpfreaks.com/topic/148007-class-or-function/#findComment-776826
Share on other sites

Ok. I am trying to learn oop a little better, so I may go that route. Are there any major performance issues? From my point of view, it seems weird using a class to do many things on many variables. To me it seems like it should be a class for each link...which is ridiculous. Is there any downfall of using a class frequently like a function?

 

Todd

Link to comment
https://forums.phpfreaks.com/topic/148007-class-or-function/#findComment-776837
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.