This repository will be strictly for uploading all my small personal projects associated with OOP-PHP and will be uploading all the small exercises here. The main projects will be uploaded separately into their own repositories.
- OOP is faster and easier to execute
- OOP provides a clear structure for the programs
- OOP helps to keep the PHP code DRY and makes the code easier to maintain, modify and debug
- OOP makes it possible to create fully reusable applications with less code and shorter development time
A class is a template for objects, and an object is an instance of class.
A class is defined by using the class
keyword, followed by the name of the class and a pair of curly braces ({})
.
Note: In a class, variables are called properties and functions are called methods!
PHP has three access modifiers: public
, private
, and protected
.
- The public access modifier allows you to access properties and methods from both inside and outside of the class. This is default
- protected - the property or method can be accessed within the class and by classes derived from that class.
- The private access modifier prevents you from accessing properties and methods from the outside of the class.