fork download
  1. <?php
  2. class Product {
  3. protected $productid;
  4.  
  5. public function getPrice() {
  6. return NULL; // or 0 or whatever default you want
  7. }
  8. }
  9.  
  10. class Toothbrush extends Product {
  11. public function getPrice() {
  12. return 5; // in USD
  13. }
  14. }
  15.  
  16. class Chainsaw extends Product {
  17. public function getPrice() {
  18. return 1000; // in USD
  19. }
  20. }
  21.  
  22.  
  23. $toothbrush = new Toothbrush();
  24. $chainsaw = new Chainsaw();
  25. var_dump($toothbrush->getPrice());
  26. var_dump($chainsaw->getPrice());
  27. ?>
Success #stdin #stdout 0.01s 20520KB
stdin
Standard input is empty
stdout
int(5)
int(1000)