OOP is in a sense a different perspective on coding-- it's about things, and manipulating properties of those things, rather than step-by-step procedures.I'm not entirely sure I like OOP better - only where it is more compact. Haven't understood enough of it yet. Seems the benefit is mostly for portability and my sites will never be used with anything but MySQL. Do you use OOP for all your php?
I should add that I agree with Adrian-- mixing OOP and other code would lead to problems in general. In the case of mysqli where there are equivalent OOP and non-OOP options, though, it's probably fine to switch, since they do exactly the same thing (as long as you check that they really do exactly the same thing!). In general, such equivalent functions won't exist (although in theory you could create them for most operations).
OOP isn't necessarily about using anything other than MySQL. It's a way to manipulate things ("objects") such as a MySQL connection. I do use OOP when it seems useful; I know others who use it for almost everything. I use it when I want to think about my code in terms of things-- for example, if I want to create a template, I might make that an object (a class called "template") and then manipulate things like $template->footer('some text'), and so forth. Rather than a series of unconnected functions, the result is all tied together with reference to an object like $template.
I think of OOP as a third level. You can draw a parallel to math sort of like this:
simple addition = line-by-line procedural code, just the basics; limited and slow
multiplication = functional programming, loops, and so forth; more powerful, faster
exponents = OOP: functions within functions, functions with properties, objects you can modify, etc.; abstract and most powerful
So in the same way that multiplication is more powerful than addition, exponents allow you to manipulate multiplication (2^4 = 2*2*2*2). In the same sense, you can get to that "next level" of programming with OOP and do some very complicated things. Or, in another way, it's just a nice way to think about certain kinds of code.
Bookmarks