Summary


This chapter took a look at object-oriented programming and file handling. Functions let you break up your programs into smaller sections, which is good because that makes them easier to write, maintain, and debug. OOP takes the next step, letting you wrap both functions and data into objects. In addition, being able to work with files on the server is very powerful, letting you create and store everything from guest books to inventory management. Here are some of the salient points in this chapter:

  • You create classes with the class statement.

  • You create objects with the new statement.

  • You can access methods and data members of an object with the arrow operator.

  • Public access means "Accessible to all".

  • Private access means "Accessible in the same class".

  • Protected access means "Accessible in the same class and classes derived from that class".

  • Constructors are special methods that let you initialize objects.

  • Inheritance lets you base one class on another.

  • You can override a method in a base class with a new version of the method simply by redefining the method in the inherited class.

  • You can open a file with the fopen function.

  • The fgets function gets a string of text from a file.

  • The fread function reads data from binary files.

  • If you want to read the entire contents of a file into a string, use the file_get_contents function.

  • If you want to write to a file, you can use the fwrite function.

  • There's also a shortcut if you want to write text to a file: you can use the file_put_contents function.



    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