Putting the classes to use
Once the classes have been created it’s just a matter of putting them to use. In a real-world situation we would be tying these classes to a database and creating multiple car objects to use in our online storefront. For the example in this article we include the objects and create a new car instance.
<?php
include('classes/Product.class.php');
include('classes/Car.class.php');
$car = new Car("Land Rover", "Range Rover", "50,000.00", "img/07_Range_Rover.jpg", "Unequaled and uncompromised, the Range Rover for 2008 remains the benchmark of luxury and refinement. Even while Range Rover stands as a classic icon, it never stands still. For 2008, Range Rover returns with refinements and the continued innovation of Terrain Response.™");
echo '<img src="'. $car->GetPhoto() .'" align="left" />';
echo '<b>'. $car->GetName() .'</b>: '. $car->GetModel();
echo '<p>Starting from: '. $car->GetPrice() .'</p>';
echo '<p>'. $car->GetDescription() .'</p>';
?>
The car instance in this example is a Land Rover, a Range Rover with a price, photo and description. Once all of these properties have been set through the constructor we can call the getters and write out the information to the current document.
About the Author
Kris Hadlock is the owner and founder of Studio Sedition (http://www.studiosedition.com), a Web design and development firm. He is the author of Ajax for Web Application Developers and has been a feature writer for numerous Web sites and design magazines. To learn more about Kris, visit his Web site at www.studiosedition.com or his blog at blog.studiosedition.com
This article originally appeared on WebReference.com.