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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.