Solution Review: Abstract Classes and Methods
Explore how to implement abstract classes and methods in PHP by creating a User abstract class and extending it with Admin and Viewer subclasses. Learn to use abstract methods and the __CLASS__ magic constant to define role-specific behavior.
We'll cover the following...
We'll cover the following...
Solution
Explanation
-
Line 2: We create a
Userabstract class with a protected$usernameproperty. -
Line 5: We add an abstract
stateYourRole()method in theUserclass. ...