I currently have a fairly large application written entirely with procedural PHP. I want to continue my PHP experience and transcode most of my applications using object-oriented methods.
There are many areas where OOP can help reduce code and make it easier to read. However, I have a few questions.
1) I understand that one class is used as a plan for any number of objects, but any one class represents only one object, not more than one. Thus, one class can represent a player, but never consisting of several players.
2) . Since I will have quite a few different classes, should I use the "Loader" class to load all of them using spl_autoload_register or just use spl_autoload_register in the program files for my application?
Edit: So my autoloader will be a class that will then create an instance to run autoload, or just a php file with a function and spl_autoload_register that I would include to avoid repeating the same code in multiple files?
3) Some of my classes depend on other classes. I have never encountered this before, so I honestly don't know the answer. If I include all classes in my main program file, but the class of my class does not include the class that it needs to use, will the player class work since the main program includes the class on which the player depends?
Edit: So, although one class can create an instance of an object of type Player, and the Player class is not directly included in this class, it will still work, because the controller class includes the Player class
4) There are several cases when I will need to work with the objects that I create. I am wondering how I should do this. For example, in my Player class, I sometimes need to send something from one player to another player. So, am I implementing a static method in the Player class that takes two players as parameters and performs the transfer, or am I doing something else?
Edit: Good, so avoid static methods. Now I have a serious problem: I have methods that are executed several times in my application, but I can not implement them as static methods. Should I implement them as instance methods? For example, sending from one player to another. Would I create an instance method that takes a Player object and sends it to him or him?
5) I have many methods that really do not belong to any instance of the class, nor do they really work like static methods. Should they be declared in their own class as static methods such as Common or similar? What is being done in practice in this situation?
Edit: Will these methods belong to a specific application file for which they are used, or possibly stored in their own functions.php file?
6) I would like to learn how to use namespaces, but my code will never be used by others, and I will never use any other code in my application. Are namespaces an overkill in my application, or would it be a good idea to learn how to use them? Regardless of whether one application has one namespace (application name?) Or does each class belong to its own namespace?
7) Finally, is it common to have one class for connecting to the database, as well as a class for network methods? My application needs both. I think that the main problem that I am encountering in converting my code to using object-oriented methods is determining which methods should be placed where they are currently all in the same monolithic file.
Thanks for any help and understanding you can provide.