» Follow me on Twitter
While most will agree that PHP was not made to be an Object Oriented
Programming (OOP) Language, I’m still sure that there are still people
who, like me, believe that making use of PHP’s OOP features helps in
making cleaner and more reusable code. This is a starter article
which I hope will sparkle your imagination in using OOP in PHP.
What are the advantages of OOP? It makes your code cleaner and
more reusable - that is, you can use the same code for different
needs. The disadvantage, hmmm, sometimes, things get slower but
since PHP is a very fast language, this slowdown isn’t noticed at all.
OOP refers to things as objects. You can think of an object as
something that does a specific task. The cathode ray tube (CRT)
for example can be an object whose specific task is to display whatever
info is sent to it. And we see CRTs in TVs, X-Ray machines,
Ultrasound equipment, Computer monitors, etc. As you see, the
basic CRT hasn’t been modified too much to fit all it’s present day
uses. The same goes with Objects in Programming.
Let’s say we make a database object. The object’s purpose is to
store, retrieve, and display data. So we make something that does
just that. Or perhaps, we want a “Fruits” object whose purpose is
to store, retrieve, and display information about fruits.
These objects can then simply be grabbed the next time you need a
database object or a fruits object - no matter what application you are
making.
As I’ve said, this article is designed to tickle your
imagination. If you are interested in using OOP in PHP, then I
would say that the best place to go is PHP’s Manual itself. You can find this manual at: http://ph.php.net/manual/en/ref.classobj.php.
Enjoy!
» Follow me on Twitter