For this PHP code exercise we will explore Object Oriented Programming in PHP by creating Shape classes: Shape.php, Rectangle.php, and Circle.php.
Shape.php is the base class. Shape class requirements are:
- A class constant named
SHAPE_TYPEwith a value of1. - Four properties with different visibilities: a public
name, a protectedlengthandwidth, and a privateid. - A constuctor which accepts a
lengthandwidthparameter to initialize the respective properties. - A public
areamethod which calculates and returns the area of theShapeobject. - A public static
getTypeDescriptionmethod which returns the stringType:with theSHAPE_TYPEconcatenated to the end. - Getter and Setter methods for the
nameproperty.
Rectangle.php should inherit from the Shape class. Rectangle class requirements are:
- A class constant named
SHAPE_TYPEwith a value of2.
Circle.php should inherit from the Shape class. Circle class requirements are:
- A class constant named
SHAPE_TYPEwith a value of3. - A protected
radiusproperty. - A constuctor which accepts a
radiusparameter and initializes theradiusproperty. **Don't forget to call theShapeclass constructor. - A public
areamethod which calculates and returns the area of theCircleobject.
Review the PHP Code Exercises documentation for more details on performing code exercises.
Jump on the PHP channel in Slack and ask your fellow students and mentors for a hint.