Page 255 - Beginning PHP 5.3
P. 255

Chapter 8: Objects
                           Summary

                           This chapter explored the large and wonderful world of object - oriented programming in PHP. You
                         learned some of the benefits of an object - oriented approach, and explored the following OOP topics:
                            ❑       The basic building blocks of OOP: classes, objects, properties, and methods
                            ❑       Creating classes and objects in PHP. You learned about property and method visibility, and how
                                to create and access properties and methods. Along the way, you studied static properties
                                and methods; class constants; parameters and return values; how to access properties from
                                within methods; and how to use hints to check the class of objects passed to methods and
                                functions
                            ❑       The concept of encapsulation  —  the idea that objects should be as self - contained as possible  —
                                  and how to put this into practice when creating your own classes
                            ❑       Three special methods that you can use to overload objects:   __get() ,  __set() , and  __call() .
                                You learned how to use these methods to intercept property accesses and method calls,
                                letting you create very powerful, flexible classes
                            ❑       Inheritance, one of the most important and powerful aspects of OOP. You learned how to create
                                child classes; how to override methods in a parent class; how to access parent methods; how to
                                prevent inheritance with the   final  keyword; and how to use abstract classes and interfaces
                                to add consistency to your classes, making them more readily adaptable and extendable for
                                yourself and for other developers
                            ❑       How to use constructors and destructors to initialize and clean up your objects
                            ❑     Using PHP ’ s   __autoload()  function to automatically retrieve class files on the fly
                            ❑       Converting objects to strings  —  and back again  —  using PHP ’ s handy   serialize()  and
                                  unserialize()  functions
                            ❑       How to find out the class of an object using   get_class()  and  instanceof
                           Though this chapter has given you enough knowledge to write fully fledged object - oriented
                         applications, there is yet more to learn about object - oriented programming in PHP, including reflection,
                         late static binding, and object cloning. To read about these more advanced topics, take a look at the
                          “ Classes and Objects ”  section of the PHP Language Reference at   http://www.php.net/manual/en/
                          langref.php . You might also like to try the exercises at the end of this chapter to put your OOP skills to
                          work. You can find the solutions to these exercises in Appendix A.

                            You have now learned the basic concepts of the PHP language. In the third and final part of the book you
                          put all this theory into practice, and learn techniques for building real - world PHP Web applications. The
                          next chapter gets the ball rolling with a look at creating and processing Web forms, which are often used
                          extensively throughout interactive Web sites.












                                                                                                         217





                                                                                                      9/21/09   9:03:48 AM
          c08.indd   217
          c08.indd   217                                                                              9/21/09   9:03:48 AM
   250   251   252   253   254   255   256   257   258   259   260