Last active
March 10, 2016 16:40
-
-
Save ryanorsinger/c2f494d760632cdab192 to your computer and use it in GitHub Desktop.
Automobile Class/Object Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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"; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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