Final Methods : final « Class « PHP






Final Methods

 
class Item {
  private $id = 555;
  final function getID() {
    return $this->id;
  }
}


class PriceItem extends Item {
  function getID() {
    return 0;
  }
}
It generates the following error:

Fatal error: Cannot override final method item::getid()
  
  








Related examples in the same category

1.final class
2.Declaring Final Classes and Methods
3.final keyword can be used to declare a class uninheritable
4.The final keyword is used to declare that a method or class cannot be overridden by a subclass