This site is mobile accessible. Press the "Tap Here" button to use a different font-size.


Smartphone icons created by Freepik - Flaticon

PHP Inheritance

The final Keyword

Error message from my server logs.

[Sun Feb 25 13:40:04.655036 2024] [php7:error] [pid 4269] [client ::1:55866] 
PHP Fatal error:  Cannot override final method Fruit::intro() in /srv/www/htdocs/W3School-WebDevelopment/php/PHPInheritancefinalKeyword.php on line 33, 
referer: http://localhost/W3School-WebDevelopment/php/7-6PHPInheritance.php
<?php
class Fruit {
  final public function intro() {
  }
}

class Strawberry extends Fruit {
  // will result in error
  public function intro() {
  }
}
?>