r/PHPhelp • u/Giuseppe_Puleri • Oct 07 '25
I don't like OOP
Good morning. I have a question for you.
You're definitely familiar with object-oriented programming. So, do you have a good understanding of PHP's interfaces, abstract classes, etc.? Do you use them?
Because I don't feel comfortable using them. I don't like OOP, and debugging also seems more cumbersome.
I prefer functional programming.
ELOQUENT IN LARAVEL Eloquent, on the other hand, seems like a good way to use OOP. However, compared to Query Builder, it's much slower.
0
Upvotes
5
u/hellocppdotdev Oct 07 '25
You don't need all the fancy things from OOP to use it effectively. Apply the concepts from functional programming to objects, for example, immutability to maintain good coding practices. OOP is just a way to keep related code together.
Or are you a "functional programmer" with a thousand line function in the index.php 😂
30
u/punkpang Oct 07 '25
You're mixing concepts and implementation.
Yes, anyone who's structuring their code ends up using abstract clases and interfaces - when it's needed. You don't use it because it exists, you use it because you need it. Why would you even ask if people use it?
Object oriented programming is about organizing your code. It's not there so you use keywords just in order to utilize it.
Your comment about Laravel's Eloquent makes no sense, it reveals you're a novice. What you're enquiring about seems to be classic XY problem.
10
u/JudithMacTir Oct 07 '25
I'm a fan of modularization, and I don’t really care if it's objects or functions. You can work clean with both and make a mess with both. It really all depends on the discipline of the developer writing the code.
4
u/Johto2001 Oct 07 '25
It's rare I need an abstract class. I usually create some interfaces in the course of my work on any non-trivial project. If it's a trivial bit of code creating an interface may be overkill for the needs of the client, but it can often be helpful anyway for reasoning and testability.
PHP supports composition and inheritance. You don't have to use either, PHP is capable of being a functional language or a procedural language. You can use composition only, or inheritance only if you prefer.
I don't see why debugging would be more cumbersome. If you are experiencing a problem you can use xdebug and step through the program just as you would with a purely functional approach, or a procedural approach.
I choose a programming style based on what's already present in any codebase I'm working on, based on the expressed preferences of the client or team I'm working with, based on the needs of the client. If the client is a small business with a procedural codebase, unless I have very good reason to suggest they change it I'm going to stick to that procedural style. Good reasons might include repetition of code in different procedures based on slightly varying use cases e.g. an order handler that processes orders from Amazon and another order handler that processes orders from a first-party website, if there's lots of duplicate code it usually makes sense to look into extracting the common code, but it doesn't always mean it has to be done in an object oriented way.
On the other hand if it's new work from scratch I will typically write in object oriented code but no more elaborate than is needed to solve the client's domain problems, with some tests in place to cover the core logic.
2
u/BFTDroid Oct 07 '25
I can work with both, and both have some pros and cons.
At work it's more functional programming, but in my latest side project it's more OOP.
It is also noteworthy that the work comes from before php 5.6 so restructuring to OOP would not be worth it...
2
u/martinbean Oct 07 '25
Businesses and its processes are much easier to model at “objects” with properties and methods to do things, then they are as mathematical functions.
2
u/mauriciocap Oct 07 '25
THUS what we use are records and operations defined over anything that satisfies a given interface, closer to ADTs than the (fortunately dead) OOP paradigm
1
u/zaphod4th Oct 07 '25
Please take OOP courses and practice more
1
u/i_live_in_sweden Oct 07 '25
I'm with you on this one, not a big fan of OOP think it makes difficult to read the code and understand what it's doing. I sometimes have to use it just because there is no other option, but if possible I try to hide those parts of the code inside a function, so I know I can call this specific function to do something, but that the function then uses OOP to do its thing is out of my mind. But then again I don't work with coding, I only do it as a hobby :)
1
u/equilni Oct 07 '25
You lost me here. Can you go into why this specific example is good OOP and how this deals with cumbersome debugging?
1
u/xreddawgx Oct 24 '25
I get where you're coming from but imagine having to query from the database that has 15 columns in over 100 + pages over and over. Its a nightmare, just write it once and call it as you need it.
0
u/RevolutionaryHumor57 Oct 07 '25
Read about dependency injection, maybe you will like strategy pattern
-2
u/liquid_at Oct 07 '25
tbh.... php is not the best language to get used to OO. Many of the really comfortable features do not work properly. But in general, OO is an interesting way to look at code, that does have its advantages.
I would not dismiss OO in general, just because it's not enjoyable in php, but I do get why people using it in php don't like it.
-2
u/alien3d Oct 07 '25