Post by BaberHi
Apologies if I have sent email to the wrong address.
I have a very simple question regarding PHP i.e
Does coding in PHP in procedural way (not object oriented) is still market
standard and not obselete?
Many thanks,
---------------
Baber
I think the answer is that you need to know and use both. There are times
when object oriented makes a lot of sense: when writing an inventory tool
that needs to track the attributes of a lot of physical objects, treating
them as data objects works really cleanly, and makes the program much
easier to read. In my view, that's arguably the biggest advantage of
object oriented code: it's frequently much more readable.
On the other hand, I've seen a script meant to move a couple of files to a
new location where the author decided to do everything object oriented, and
spent forty or fifty lines defining classes for the files and folders they
needed. That was, in all honesty, kind of dumb, since I rewrote it as
about a fifteen line procedural script. It ran faster and with less
resources required, and probably took a tenth of the time to write.
(Nevermind that PHP isn't really a fantastic choice for command line work
anyway, and writing a one-liner to call a perl script probably would have
been a lot better...)
Basically, both approaches have uses, and if you only learn one, or decide
that one is always universally better, you'll be making your life harder
than it needs to be at least some of the time.
Andy McKenzie