Getting Started with Objects with PHP V5
By Matt Zandstra2005-07-01
A class can be used directly as a neat way of organizing data and functionality, very much like a bunch of functions and variables. This is to ignore a powerful dimension, however. Classes can be used to generate multiple instances in memory. Such instances are called objects. Each object has access to the same set of functions (called methods in an object-oriented context), and variables (called properties or instance variables), but the actual value of each variable may differ from object to object.
Think about a unit in a role-playing game -- a tank, perhaps. A class may lay down a set of variables for tanks: defensive and offensive capability, range, health, and so on. The class may also define a set of functions, including move() and attack(). While the system contains one tank class, this class may be used to generate tens or hundreds of tank objects, each potentially with its own characteristics of health or range. A class, then, is a blueprint or template for use in generating objects.
Perhaps the easiest way to understand classes and objects is to create some.
Tutorial pages:
|
First published by IBM DeveloperWorks
|
|||||||||
You might also want to check these out:
|
Link to This Tutorial Page!

