Using OOP in your PHP scripts allows you to model your code very closely after real life, which make things much easier for you. It also allows you to easily re-use code by sharing your classes.
PHP has a very rich OOP architecture, much of which you may never find the need to use - if __get(), __set() and other magic functions seem pointless to you, do not worry about it.
Use access modifiers like private and protected to make sure your data is accessed precisely as you intend for it to be accessed - don't let other programmers abuse your classes!
Class inheritance allows you to build up a complicated infrastructure of classes, each building on its parent - this is one of OOP's most valued features, so make good use of it.
If you are looking for multiple inheritance, you are looking at the wrong language - the best PHP supports is interfaces, which are a simple way to ensure a given class supports a set of functions.
If this was helpful, please take a moment to tell others about Hacking with PHP by tweeting about it!
Next chapter: Exercises >>
Previous chapter: A more complex OOP website
Home: Table of Contents
Copyright ©2015 Paul Hudson. Follow me: @twostraws.