This site is mobile accessible. Press the "Tap Here" button to use a different font-size.


Smartphone icons created by Freepik - Flaticon

PHP Object

My car is a black Volvo!
My car is a red Toyota!

<?php

// define object Car
class Car {
  public $color;
  public $model;
  public function __construct($color, $model) {
    $this->color = $color;
    $this->model = $model;
  }

// defines public message
  public function message() {
    return "My car is a " . $this->color . " " . $this->model . "!";
  }
}

// displays messages
$myCar = new Car("black", "Volvo");
echo $myCar -> message();
echo "<br>";
$myCar1 = new Car("red", "Toyota");
echo $myCar1 -> message();
?>