Skip to content

Instantly share code, notes, and snippets.

@ryanorsinger
Last active March 10, 2016 16:40
Show Gist options
  • Select an option

  • Save ryanorsinger/c2f494d760632cdab192 to your computer and use it in GitHub Desktop.

Select an option

Save ryanorsinger/c2f494d760632cdab192 to your computer and use it in GitHub Desktop.
Automobile Class/Object Example
<?php
class Automobile
{
public $make;
public $model;
public $color;
public $miles;
public function __construct($make, $model, $color)
{
$this->make = $make;
$this->model = $model;
$this->color = $color;
}
public function getDescription()
{
return $this->color . " ". $this->make . " " . $this->model;
}
public function save()
{
// turn object into a string
// write the string to a file
}
public function __destruct()
{
echo "The Automobile object was destroyed";
}
}
<?php
require_once "Automobile.php";
$make = 'vw';
$model = 'bug';
$color = "papayawhip";
$car1 = new Automobile($make, $model, $color);
$car1->miles = inputGet('miles');
$car1->save();
echo $car1->getDescription();
$yourCar = new Automobile('audi', 'A4', 'pink');
echo $yourCar->getDescription();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment