Chapter7.Object-Oriented Programming and File Handling


Chapter 7. Object-Oriented Programming and File Handling

In this chapter, we're going to take a look at two important PHP topicsobject-oriented programming (OOP) and file handling. You don't absolutely need object-oriented programming to make your pages work in PHP. However, if you're going to be sticking with PHP for the long term, or if you're building substantial web applications, then OOP holds some gems for you.

OOP was first introduced to handle larger programming tasks. As we've seen, functions let you break up your programs into smaller sections, which is a great help. OOP takes the next step, letting you wrap both functions and data into objects. This lets you divide up your scripts even further because an object can contain not only a group of functions, but also the data those functions may need. For example, think of what goes on inside a refrigerator: pumps, thermostats, fans, and more are all working together. If you had to work them all by hand, it would be a disaster, but if you wrap them all into a convenient objecta refrigeratorall you must remember is that the refrigerator cools food; the details are internal.

In the same way, wrapping functions and data together lets you break up long scripts. For example, one object might handle the screen display, another might validate data, another might work with a database, and so on.



    Spring Into PHP 5
    Spring Into PHP 5
    ISBN: 0131498622
    EAN: 2147483647
    Year: 2006
    Pages: 254

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net