Defining and Using Object Properties
Instantiate the Car ClassSome properties:
The Beetle's color is red.
The Mustang's manufacturer is Ford.
The $beetle Object:
Car Object ( [model] => [color] => red [manufacturer] => Volkswagen [type] => [_speed:Car:private] => 0 [_extraData:Car:private] => Array ( ) )
The $mustang Object:
Car Object ( [model] => [color] => green [manufacturer] => Ford [type] => [_speed:Car:private] => 0 [_extraData:Car:private] => Array ( ) )Instantiate another car
I'm driving a blue Chrysler Dodge Caliber.
Top speed reached after acceleration:
Current speed: 10 mphCurrent speed: 20 mph
Current speed: 30 mph
Current speed: 40 mph
Current speed: 50 mph
Current speed: 60 mph
Current speed: 70 mph
Current speed: 80 mph
Current speed: 90 mph
Current speed: 100 mph
Switch statement to reveal Car type
hatchbackInstantiate another car
I'm driving a red Volkswagen Beetle. p>
Stepping on the gas...
Current speed: 10 mph
Current speed: 20 mph
Current speed: 30 mph
Current speed: 40 mph
Current speed: 50 mph
Current speed: 60 mph
Current speed: 70 mph
Current speed: 80 mph
Current speed: 90 mph
Current speed: 100 mph
Top speed! Slowing down...
Current speed: 90 mph
Current speed: 80 mph
Current speed: 70 mph
Current speed: 60 mph
Current speed: 50 mph
Current speed: 40 mph
Current speed: 30 mph
Current speed: 20 mph
Current speed: 10 mph
Current speed: 0 mph
Stopped!
28This car's MPG is: 28
Instantiate another car
green A cat is not a car. We try to use the paint() method to paint the cat
Instantiate the Garage Class
Lucky the cat is not a car object you should not be able to paint it, yet we did
The error stops all processing but doesn't show up otherwise.
Letting the compiler know by putting the type in the function declaration alerts the compiler
Instantiate the Car Class again
The car's color is aqua-marine
Instantiate the Car Class again
Some properties:
My car's manufacturer is Volkswagen.
My car's engine size is 1.8.
My car's fuel type is .
The $myCar Object:
Car Object ( [model] => Beetle [color] => red [manufacturer] => Volkswagen [type] => [_speed:Car:private] => 0 [_extraData:Car:private] => Array ( [engineSize] => 1.8 [otherColors] => Array ( [0] => green [1] => blue [2] => purple ) ) )Instantiate the Square class
Instantiate the ShapeInfo() class
The shape's color is green, and its area is 9.
Instantiate the Rectangle ClassInstantiate the ShapeInfo() class
The shape's color is yellow, and its area is 0.
Instantiate the Circle ClassMy circle is red and its area is 50.265482457437.
Instantiate the SquareMy square is green and its area is 9.
Instantiate the Polygon ClassInstantiate the ShapeInfo Class
The shape's color is yellow, and its area is 20.
Instantiate the Television ClassInstantiate TennisBall Class
Instantiate StoreManager Class
There are 100 42-inch televisions and 100 yellow tennis balls in stock.
Selling a television...
Selling two tennis balls...
There are now 99 42-inch televisions and 98 yellow tennis balls in stock.
Instantiate the Person ClassHarry Walters, age 28
Instantiate the Person Class
Instantiate the Person Class
Instantiate the Person Class
Serialize Person Object Harry
Harry is now serialized in the following string: 'O:6:"Person":6:{s:18:" Person _firstName";s:5:"Harry";s:17:" Person _lastName";s:5:"Wayne";s:12:" Person _age";i:28;s:3:"age";i:29;s:8:"frstName";s:13:"Harry Houdini";s:8:"lastName";s:23:"Magician Extraordinaire";}'
Converting 'O:6:"Person":6:{s:18:" Person _firstName";s:5:"Harry";s:17:" Person _lastName";s:5:"Wayne";s:12:" Person _age";i:28;s:3:"age";i:29;s:8:"frstName";s:13:"Harry Houdini";s:8:"lastName";s:23:"Magician Extraordinaire";}' back to an object...
UnSerialize Harry
Harry's age is: 29
Hary's name is: . Magician Extraordinaire .
Instantiate the User Class
The original user object:
User Object ( [username] => harry [password] => monkey [loginsToday] => 3 )
Serializing the object...
The user is now serialized in the following string:
O:4:"User":2:{s:8:"username";s:5:"harry";s:8:"password";s:6:"monkey";}
Converting the string back to an object...
Yawn... what's for breakfast?
Saving this object to the database...
The unserialized object:
User Object ( [username] => harry [password] => monkey [loginsToday] => )