Back To Class - If Wishes Were Prancing Horses...
(Page 3 of 9 )
Given the class, it's now simple to spawn as many Automobiles as you like, and adjust the individual properties of each. Take a look:
<?
// let's spawn a couple of cars
// this is mine...
$his = new Automobile;
$his->make = "Ferrari";
$his->colour = "Black";
$his->shape = "Cigar";
// ...and this is yours
$hers = new Automobile;
$hers->make = "Porsche";
$hers->colour = "Silver";
$hers->shape = "Torpedo";
// hey...i can dream, can't i
// i feel like taking mine out for a spin
$his->start();
// speed limit? you must be joking!
$his->accelerate(180);
// joining me, are you?
$hers->start();
$hers->accelerate(150);
// oops...was that a speed trap?
$his->decelerate(80);
$hers->decelerate(80);
// busted!
$his->stop();
$hers->stop();
?>
As the illustration above shows, once new objects are
defined, their individual methods and variables can be accessed and modified independent of each other. This comes in very handy, as the next few pages will show.
Next: New Cars For Old >>
More PHP Articles
More By icarus, (c) Melonfire