8. - PHP Online

Form of PHP Sandbox

Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php in the places where the PHP script should be executed.



Your result can be seen below.

Result of php executing





Full code of 8..php

  1.  
  2. <?php
  3. class car
  4. {
  5.   public $thing;
  6.   public function __construct($thing) {
  7.     $this->thing = $thing;
  8.   }
  9.   public function message() {
  10.     return "My car is " . $this->thing;
  11.   }
  12. }
  13. class model
  14. {
  15.   public $model;
  16.   public function __construct($other) {
  17.     $this->other = $other;
  18.   }
  19.   public function message() {
  20.     return "My car is a " . $this->other;
  21.   }
  22. }
  23. class complaint
  24. {
  25.   public $model;
  26.   public function __construct($complaint,$why) {
  27.     $this->complaint = $complaint;
  28.     $this->why = $why;
  29.   }
  30.   public function message() {
  31.     return "I wish it was a " . $this->complaint. " ".$this->why;
  32.   }
  33. }
  34. $myCar = new Car("grey");
  35. echo $myCar -> message();
  36. echo "<br>";
  37. $myCar = new model("SUV");
  38. echo $myCar -> message();
  39. echo "<br>";
  40. $myCar = new model("Ford");
  41. echo $myCar -> message();
  42. echo "<br>";
  43. $myCar = new complaint("red", "Toyota");
  44. echo $myCar -> message();
  45.  
  46. ?>
  47.  
File Description
  • 8.
  • PHP Code
  • 24 Feb-2021
  • 880 Bytes
You can Share it: