Abstract classes in OOP
Ghulam Mujtaba
Posted on July 25, 2024
Abstract classes in PHP are classes that cannot be instantiated on their own and are designed to be inherited by other classes. They can contain both abstract and concrete methods.
Abstract classes are defined using the abstract
keyword, and any class that contains at least one abstract method must be declared as an abstract class.
Characteristics
- Cannot be instantiated directly
- Must be inherited by another class
- Can contain both abstract and concrete methods
- Abstract methods must be implemented by child classes
- Concrete methods can be used by child classes without implementation
<?php
abstract class AchivementType
{
public function name(){
$class = (new ReflectionClass($this))->getShortName();
return trim(preg_replace('/[A-Z]/','$0', $class));
}
public function icon()
{
return strtolower(str_replace('','-', $this->name())).'.png';
}
abstract public function qualifier($user);
}
I hope that you have clearly understood the concept of abstract classes.
💖 💪 🙅 🚩
Ghulam Mujtaba
Posted on July 25, 2024
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.