fork download
  1. <?php
  2.  
  3. class Book
  4. {
  5. protected $price;
  6. protected $title;
  7.  
  8. public function setPrice($par)
  9. {
  10. $this->price = $par;
  11. return $this;
  12. }
  13.  
  14. public function getPrice()
  15. {
  16. return $this->price;
  17. }
  18.  
  19. public function setTitle($par)
  20. {
  21. $this->title = $par;
  22. return $this;
  23. }
  24.  
  25. public function getTitle()
  26. {
  27. return $this->title;
  28. }
  29. }
  30.  
  31. $physics = new Book;
  32. $maths = new Book;
  33. $chemistry = new Book;
  34.  
  35. $physics->setTitle( "Physics for High School" )->setPrice( 10 );
  36. $chemistry->setTitle( "Advanced Chemistry" )->setPrice( 15 );
  37. $maths->setTitle( "Algebra" )->setPrice( 7 );
  38.  
  39. echo $physics->getTitle() . PHP_EOL;
  40. echo $chemistry->getTitle() . PHP_EOL;
  41. echo $maths->getTitle() . PHP_EOL;
  42. echo $physics->getPrice() . PHP_EOL;
  43. echo $chemistry->getPrice() . PHP_EOL;
  44. echo $maths->getPrice() . PHP_EOL;
Success #stdin #stdout 0.01s 24400KB
stdin
Standard input is empty
stdout
Physics for High School
Advanced Chemistry
Algebra
10
15
7