Final class in PHP is a class that can not be inherited. or we can say that it can not be extended . It basically protect the methods of class that is to be overriden by the other child classes present there.
For declaring a class as final, we have to prefix the class with 'final' keyword .
Example :
final class baseclass
{
public function mymethod() {
echo "baseclass method";
}
}
class derivedclass extends baseclass
{
public function mymethod() {
echo "derivedclass method";
}
}
$c= new derivedclass();
$c->mymethod();
Given example have a base class which is declared as final .So it can not be inherited.if in any case any of
derived class tries to extending this define baseclass then you will get the compile error as output.
0 Comment(s)