Last active
March 31, 2018 06:47
-
-
Save kselax/4c751a2fcb597eeeb3f3c84e01c87cd8 to your computer and use it in GitHub Desktop.
PHP OOP final classes and methods
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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