When Does It Become Necessary To Use Classes In Php?

November 16th, 2009 by CTO WebOjO.com website designers Lahore Pakistan Leave a reply »

When do classes make things a lot easier and what are some good ways to use them. I have used classes in C++ but mostly for structuring data, but since data is already in tables, how can i use OOP properly in PHP?

Advertisement

3 comments

  1. just "JR" says:

    Actually, it is not “necessary”.
    It is only useful IF you require a fonction to be called many times, or if you use a class developed by someone else, too complex for YOU to design!
    Say you need to made a downloadable document generated in PhP using a DB, and presented in PDF format.
    - You can learn how to design a file in PDF format (pretty complex)
    - You can use a free class that does it for you (600kb of code!) You will just have to learn HOW to use the class.

  2. Peter K says:

    Use Classes when you have a lot of similar objects. For example, a class that makes information pages. Each page has a different format so you implement render differently. If you have it as a class you just say render() and it calls the appropriate render function no matter what page you are using.

  3. Jewish Boy says:

    Classes are never really necessary. Classes could be a easy way to organize your scripts. But you never need to use them.