r/PHPhelp • u/thegamer720x • Apr 08 '25
Right way to PHP OOP Implementation
Hi, I'm working as a full stack php developer. My job mainly requires procedural style php code. So I'm quite well versed with it.
Now, I have been trying to learn php oop. But no matter how many videos or guides i see, its still confusing.
Main confusion comes from
- File organization
- should each class be a seperate php file
- should utility class ( sanitization, uppercase, lowercase etc) be all combined in one?
- how to use one class in another class
- How to create class
- what should constitute a class. Should user be a class defining creation / deletion / modification of users
- what exactly should a constructor of class do ( practically)
I'm still trying to defer mvc architecture for now. In order to understand how the design and flow for oop program should be done
Any and all help with this is helpful. I understand the basics, but having difficulty with irl implementation. Please recommend any guide that helps with implementation rather than basics.
Thanks
View all comments
Show parent comment
1
u/clusterconpuntillo Apr 09 '25 edited Apr 09 '25
I mean if I want to know how to write a class and why, the explanation in that tutorial is not ok. If I actually wanna make a framework just for learning purposes I would try to write it from scratch. One of the fundamentals on making an HTTP framework, as the tutorial suggests, is the Request / Response architecture. The tutorial encourages you to use symfony components for that and not to write your own. Nothing to learn there
Edit: lot of typo correction's