Classes and objects are powerful OOP concepts - and PHP4 supportsthem too. This article explains some basic OO entities (including classes,constructors and extensibility) with examples of a table builder and aguestbook.
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.