Beginning Object Oriented Programming in PHP - Objects - The Magic Box
(Page 2 of 6 )
Imagine a box. It can be any type of box you want: a small jewelry box, a large crate, wooden, plastic, tall and thin, Short and wide...
Next, imagine yourself placing something inside the box: a rock, a million dollars, your younger sibling...
Wouldn't it be convenient if we could walk up to the box and just ask it to tell us what's inside instead of opening it ourselves? Actually, we can!
<?php $mybox = new Box("Jack"); echo $mybox->get_whats_inside(); ?> |
Here the variable $mybox represents our self-aware box (also known as an object) which will be built by new--the world's smallest engineering and construction team. We also want to place Jack inside the box when it is built. When we want to ask the box it's contents, we'll apply a special get_whats_inside function to $mybox.
The code won't run quite yet, though. We haven't supplied new with the directions for him and his team to construct our box and PHP doesn't know what the function get_whats_inside is supposed to do.
Next: Classes >>
More Programming Basics Articles
More By bluephoenix
|
| · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | | |
|