Challenge: Data Handling Using the PDO Extension and Abstract Methods
A hands-on exercise to test your knowledge of PHP 8 best practices.
We'll cover the following
Task 1
The code should follow strict typing.
Implement a class that implements the abstract method of the trait that performs addition.
Define a trait that will be used in another class. This trait should contain two methods:
The first method is an abstract method representing a generic mathematical operation.
The other is not abstract and is implemented within the trait. It should be a wrapper around the first method.
Finally, echo the results to the console.
Instructions
Define the addition math operation in the
Calculator
class.Modify the
Calculator
class to implement theperformOperation
method, which will perform the specific math operation. In this case, you’ll add$b
and$a
.Create an instance of the
Calculator
class.Use the
calculate
method to perform the specific math operation with the provided numbers (10.5 and 5.2 in this case).Print the result to the screen.
Coding playground
Get hands-on with 1200+ tech skills courses.