如何管理PHP类和函数?

I use to maintain a PHP class and lot of functions inside that. It may cross more than 50 functions inside a class for developing a portal. But i always use a single class only. Is this is a good habit or do we have better option than this?

My class looks like this

class myClass{
 public function one($value)
 {
     //Do something
 }

 public function Two($value)
 {
     //Do something
 }

 public function Three($value)
 {
     //Do something
 }

 public function Four($value)
 {
     //Do something
 }
}

Now inside this class i may write more than 50 functions.. So comparatively file size of this document will be more than other files. SO am asking is this is a proper method of handling the PHP class and functions?

A few years back, I have been having the same problem.

If it bothers you that you have too much code in one class (one file) and dividing code into multiple classes would be pointless for your type of use, you can implement MVC architecture that will help you devide the code based on it's functionality and purpose. By doing so correctly you will make the code easier to read and customize.

50+ functions in a class is definitely a lot. i personally would try to find a way to break that down further logically into separate concerns.

You may have a look in UML class diagramms. With a diagramm you can model your system to create a fine architecture, from the start. Maybe in your case it may be only 2-3 classes. Like Dejv wrotes, a development pattern like MVC gives you hints what classes and in what what relationships the system could be.

Give you an example

lets say you use a minimial MVC architecture. You will have 3 classes. For the view you could call it "gui_main", the controller "controller" and the model "engine".

I think that 50 functions are quite many for one class. Maybe it is easier for a small application to use one class only. But in a long term, I would thing that smaller classes, that are well designed before, will be more flexibel and easier to maintain later. The nice thing about classes are, that you try to group similar behaviors and attributes in a class. Later you can guess from the class name, what behaviors and attributes they may have, I just made myself good experiences with many classes (38).

Definitely 50 methods in one class is bad practice. One of OOP pros is reusability and low code complexity. Then more methods in your class, then it became less reusable and have higher code complexity.

Follow PHP Mess Detector recommended settings and keep your classes with not more than 10 methods (see TooManyMethods error). Explanation of this from PHPMD:

A class with too many methods is probably a good suspect for refactoring, in order to reduce its complexity and find a way to have more fine grained objects.