Objects
The object-oriented programming (OOP) paradigm has been around for many years now, although the degree to which it is support varies widely across languages. C++, for example, is object-oriented C, and, as some purists would say, implements more OOP functionality than even Java does.
Before PHP 5 came along, OOP support in PHP was quite flaky and more of a hack than a serious attempt. As a result the few that used it often regretted the choice, and it is not surprising that the whole system got a full rewrite in PHP 5 - it is now much more advanced and flexible, and should please just about everyone.
Topics covered in this chapter are:
-
Objects and classes defined
-
Class inheritance
-
Access control
-
Runtime type information
-
Abstract and final properties and functions
-
Constructors and destructors
-
Magic functions
Chapter contents
- 6.1. Conceptual overview
- 6.2. Classes
- 6.2.1. Defining a class
- 6.2.2. How to design your class
- 6.2.3. Basic inheritance
- 6.2.4. Overriding functions
- 6.3. Objects
- 6.4. Variables
- 6.5. The 'this' variable
- 6.6. Objects within objects
- 6.7. Access control modifiers
- 6.7.1. Public
- 6.7.2. Private
- 6.7.3. Protected
- 6.7.4. Final
- 6.7.5. Abstract
- 6.7.6. Iterating through object variables
- 6.8. Object type information
- 6.9. Class type hints
- 6.10. Constructors and destructors
- 6.10.1. Parent constructors
- 6.10.2. Destructors
- 6.10.3. Deleting objects
- 6.11. Copying objects
- 6.12. Comparing objects with == and ===
- 6.13. Saving objects
- 6.14. Magic functions
- 6.14.1. __autoload()
- 6.14.2. __get()
- 6.14.3. __set()
- 6.14.4. __call()
- 6.14.5. __toString()
- 6.15. Static data
- 6.16. Helpful utility functions
- 6.17. Interfaces
- 6.18. Deferencing object return values
- 6.19. The Object-Oriented Website
- 6.19.1. A basic OOP site
- 6.19.2. A more complex OOP website
- 6.20. Summary
- 6.21. Exercises
- 6.22. Further reading
- 6.23. Next chapter



Copyright 2010 Future Publishing Limited (company
registered number 2008885), a company registered
in England and Wales whose registered office is at
Beauford Court, 30 Monmouth Street, Bath, BA1 2BW, UK