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
Want to learn PHP 7?
Hacking with PHP has been fully updated for PHP 7, and is now available as a downloadable PDF. Get over 1200 pages of hands-on PHP learning today!
If this was helpful, please take a moment to tell others about Hacking with PHP by tweeting about it!
Next chapter: Conceptual overview >>
Previous chapter: Next chapter
Jump to: Objects Conceptual overview Classes Defining a class How to design your class Basic inheritance Overriding functions Objects Variables The 'this' variable Objects within objects Access control modifiers Public Private Protected Final Abstract Iterating through object variables Object type information Class type hints Constructors and destructors Parent constructors Destructors Deleting objects Copying objects Comparing objects with == and === Saving objects Magic functions __autoload() __get() __set() __call() __toString() Static data Helpful utility functions Interfaces Deferencing object return values The Object-Oriented Website A basic OOP site A more complex OOP website Summary Exercises Further reading Next chapter
Home: Table of Contents
Copyright ©2015 Paul Hudson. Follow me: @twostraws .