Skip to content

Instantly share code, notes, and snippets.

@kselax
Last active March 31, 2018 06:47
Show Gist options
  • Select an option

  • Save kselax/4c751a2fcb597eeeb3f3c84e01c87cd8 to your computer and use it in GitHub Desktop.

Select an option

Save kselax/4c751a2fcb597eeeb3f3c84e01c87cd8 to your computer and use it in GitHub Desktop.
PHP OOP final classes and methods
<?php
echo "<p>Test final</p>";
// class couldn't be used like a parent class
final class A{
public function __construct(){
echo __CLASS__."<br>";
}
}
class C{
// method couldn't be overwritten
final public function draw(){
echo __CLASS__.' draw<br>';
}
}
// this won't work, you can't use finel classes as super classes
// class B extends A{
class B extends C{
public function __construct(){
echo __CLASS__."<br>";
}
// impossible overwrite final method
// public function draw(){
// echo __CLASS__.' draw<br>';
// }
}
$obj=new B();
$obj->draw();
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment