Welcome to the second article in my series on object-oriented PHP programming. In the first article, we looked at the basics of OOP in PHP — including the concepts of classes, objects, properties and methods — and we saw how to create basic classes and objects in PHP.
In this article, you’re going to delve a bit deeper into properties and methods in PHP. This will give you a solid grounding when it comes to using objects in PHP, before we move on to more advanced topics such as inheritance in later articles.
These are the concepts you’ll explore in this article:
- Constructors and destructors, which let your objects do specific things whenever they’re created or deleted
- Static properties and methods, for creating class properties and methods that are not tied to specific objects
- Class constants, which are handy for storing fixed values related to a class
- Type hinting, for restricting the types of objects that can be passed to a method
__set()magic methods for overloading property accesses
__call()magic method for overloading method calls
All set to delve deeper into properties and methods? Great! Let’s go!