fork download
  1. <?php
  2.  
  3. abstract class Foo
  4. {
  5. protected $name;
  6.  
  7. public function __construct($name)
  8. {
  9. $this->name = $name;
  10. }
  11.  
  12. public function getName()
  13. {
  14. return $this->name;
  15. }
  16. }
  17.  
  18. final class Bar extends Foo
  19. {
  20. public function __construct($name)
  21. {
  22. parent::__construct($name);
  23. }
  24. }
  25.  
  26. $bar = new Bar('Jan');
  27. echo $bar->getName();
  28.  
  29.  
  30. $foo = new Foo('Jan');
  31. echo $foo->getName();
  32.  
Runtime error #stdin #stdout #stderr 0s 52488KB
stdin
Standard input is empty
stdout
Jan
stderr
PHP Fatal error:  Cannot instantiate abstract class Foo in /home/FMM7Cv/prog.php on line 30