Using Abstract Classes Correctly with PHP Code Examples in 2023

What is an Abstract Class in PHP An abstract class in PHP is a class with at least one not implemented method. You cannot use an abstract class directly but must extend it with a child class. The child classes are supposed to provide an implementation for these abstract methods. Using an Abstract Class in PHP Create an abstract class in PHP by adding the modifier "abstract" before noting the access level. Do the same thing for any methods you want to require child classes to implement. You can see the below for an example. Abstract Class Code Example <?php abstract public class Bird { abstract public function fly() {} public function walk() { // do something concrete here } public class Flamingo extends Bird { public function fly() { // do something here } } But why and what is the purpose of all this? That’s precisely why we…

read more

Using Interfaces in PHP Correctly with Code Examples in 2023

What is an interface in PHP? Interface in PHP or more generally in Object Oriented Programming (OOP) is an idea of having a higher level of representation or more precisely an abstraction over more specialized and concrete classes. That sounds like a philosophical thing.  Worry not, because we have a lot to say about interfaces and what they are in Object Oriented Programming (OOP). Stay tuned till the end to learn more. What’s with the term ‘interface’? The term ‘interface’ changes meaning in different contexts. Perhaps, that’s a reason why it is often a misunderstood term. So, let’s see the different meanings of this term in different contexts. User Interface / User Experience (UI/UX) Designers use the term interface for visible and interactive elements of an application, more generally called the ‘Frontend’ of an application. In fact, the ‘User Interface’ (UI) is an important aspect of human & machine interactions.…

read more