php - Function vs Objects Best Practice -


I am thinking that the best practice about tasks and objects, for example, I take an action called Clean-A-Action Want to This will take my data as input and will organize it and return it.

Now I can do it in two ways. Using a simple function and using the second class.

  function: $ data = free ($ data); Class: $ clean = new clean (); $ Data = $ clean-> Clean ($ Clear);  

Now the advantage in creating a square is that I do not need to load the class first. I can just use php's autoload feature to do this.

Another example database class is now using a different class for all DB connectivity. But we usually have the same object in that class, is it not unlike the definition of class and objects like this that we are using the orbit to make only one object underlying?

I think the best practice about when and when to use a function is to use the function? Any guidelines?

Thank you, Alec

I personally call a 'data' object It has a clean method under handling.

This pattern will allow you to count the number of tasks done on the data, while it will all be placed in a very small self-contained chuck.


Comments