fork download
  1. <?php
  2.  
  3. abstract class Form {
  4. abstract protected function do_shit();
  5.  
  6. public function f() {
  7. $this->do_shit();
  8. }
  9.  
  10. public static function build($type) : Form {
  11. return new $type();
  12. }
  13. }
  14.  
  15. class FormA extends Form {
  16. protected function do_shit() : void {
  17. echo "A";
  18. }
  19. }
  20. class FormB extends Form {
  21. protected function do_shit() : void {
  22. echo "B";
  23. }
  24. }
  25.  
  26. class FormC extends Form {
  27. protected function do_shit() : void {
  28. echo "C";
  29. }
  30. }
  31. class FormD extends Form {
  32. protected function do_shit() : void {
  33. echo "D";
  34. }
  35. }
  36. class FormE extends Form {
  37. protected function do_shit() : void {
  38. echo "E";
  39. }
  40. }
  41.  
  42.  
  43. $f = Form::build('FormC');
  44. $f->f();
  45.  
  46.  
  47.  
Success #stdin #stdout 0.02s 24280KB
stdin
Standard input is empty
stdout
C