PHP OOP-Final Keyword

In PHP, we can’t declare variables as Final. Only classes and class methods are allowed to use the Final keyword.

If we define a class method as Final, the child class will not be able to override that method of the parent class.

Similarly to methods, declaring a class as Final prevents it from being expanded.

<?php
class A	
{
final function sum($x,$y)
{
$add=$x+$y;
echo "Sum of given no=".$add;
}
} 
class B extends A
{
 function sum($x,$y,$z)
{
$add=$x+$y+$z;
echo "Sum of given no=".$add;
 }
}	 
$obj= new B();
$obj->sum(100,50);
?>
<?php
final class A	
{
function sum($x,$y)
{
$add=$x+$y;
echo "Sum of given no=".$add;
}
} 
class B extends A
{
 function sum($x,$y,$z)
{
$add=$x+$y+$z;
echo "Sum of given no=".$add;
 }
}	 
$obj= new B();
$obj->sum(100,50);
?>