Php-mysql Course

Final classes

Inheritance allows for enormous flexibility within a class hierarchy. You can create subclasses to extend the functionality of a base class, but PHP OOP gives the posibility to create classes that cannot be extended. Such a class is called final class.
A final class is declared by adding the final keyword before the class word.
  - For example:
<?php
// base class (declared final)
final class Base {
  // ... PHP code
}

// define a child class derivated from Base
class BaseChild extends Base {
  // ... PHP instructions
}
?>
Running this code will generate the following error:
Fatal error: Class BaseChild may not inherit from final class (Base) in ...

Final methods

A normal method (public or protected) can be overridden in the child class. If you want a method to remain fixed and unchanging, prefix the definition with the final keyword.
A final method cannot be overridden.
  - For example:
<?php
// base class
class Base {
  // final method
  final public function testMethod() {
    echo 'This is a final method';
  }
}

// define a child class derivated from Base
class BaseChild extends Base {
  // override the testMethod()
  public function testMethod() {
    echo 'Another text';
  }
}
?>
This example will generate the following error:
Fatal error: Cannot override final method Base::testMethod() in ...

By declaring a class or method final, you limit the flexibility given by inheritance, so, use final with care.

Daily Test with Code Example

HTML
CSS
JavaScript
PHP-MySQL
Which tag defines the clickable areas inside the image map?
<map> <img> <area>
<img src="image.jpg" usemap="#map1">
<map name="map1">
  <area shape="rect" coords="9, 120, 56, 149" href="#">
  <area shape="rect" coords="100, 200, 156, 249" href="#">
</map>
Which CSS property defines what is done if the content in a box is too big for its defined space?
display overflow position
#id {
  overflow: auto;
}
Click on the event which is triggered when the mouse is positioned over an object.
onclick onmouseover onmouseout
document.getElementById("id").onmouseover = function(){
  document.write("Have Good Life");
}
Indicate the PHP variable that contains data added in URL address after the "?" character.
$_SESSION $_GET $_POST
if(isset($_GET["id"])) {
  echo $_GET["id"];
}
PHP OOP - Final Classes and Methods

Last accessed pages

  1. GraidleChart Create Graphic Charts (1993)
  2. Set custom message for required and field validation (1380)
  3. Area and Perimeter Calculator for 2D shapes (10136)
  4. A simple script ActionScript 3 (4404)
  5. Chaining multiple jQuery effects (4904)

Popular pages this month

  1. Courses Web: PHP-MySQL JavaScript Node.js Ajax HTML CSS (497)
  2. PHP-MySQL free course, online tutorials PHP MySQL code (91)
  3. Read Excel file data in PHP - PhpExcelReader (55)
  4. The Mastery of Love (43)
  5. The Fifth Agreement (42)