Class
A class is a code template used to generate objects. It is some sort of a blueprint that describes the object.In PHP a class name can be alphanumerical string that cannot begin with a number. Class code must be enclosed with braces and it consists of attributes and operations.
Example
class Car {
//some variable
private $owner;
//operation
public function setOwner() {
//something to do ...
}
}
Object
An object is data that is structured according to the template defined in a class. It is instance of a class.Example
$myCar = new Car();In real world, you'll often find many individual objects all of the same kind. As an example, there may be thousands of other cars in existence, all of the same make and model even owned by the same person. Each car was built from the same blueprint. In object-oriented terms, we say that the car is an instance of the class of objects known as cars.
$obamasCar = new Car();
print $myCar; //outputs Object id #1
print $obamasCar; //outputs Object id #2
Email this
Hits: 968
Comments (0)

Write comment


