objects and classes
Moderator: General Moderators
- shiznatix
- DevNet Master
- Posts: 2745
- Joined: Tue Dec 28, 2004 5:57 pm
- Location: Tallinn, Estonia
- Contact:
objects and classes
i have a few questions about classes and objects. first of all what is a object? also what does $this->somthing do and were does "$this" and "somthing" come from? i dont think i quite understand the concept of classes maybe i can get a good understanding of the very basics of classes?
- Skittlewidth
- Forum Contributor
- Posts: 389
- Joined: Wed Nov 06, 2002 9:18 am
- Location: Kent, UK
Code: Select all
$this ->somethingI'll give it my best shot [$i->giveBestShot();]
So basically an object is a ball that you are holding in your hand. There are methods that you are able to use in terms of this ball. For example, ball->getColor() may return the color of the ball. The ball has a field within it, called color which stores the value 'red.'
Lets look at this programmatically:
"$this->" is used within the ball, to refer to the object's own variables.
Hope that was a little bit helpful
So basically an object is a ball that you are holding in your hand. There are methods that you are able to use in terms of this ball. For example, ball->getColor() may return the color of the ball. The ball has a field within it, called color which stores the value 'red.'
Lets look at this programmatically:
Code: Select all
class Ball {
var color;
function Ball ( $col ) {
$this->color = $col;
}
function getColor ( ) {
return $this->color;
}
}
$b1 = new Ball ( "Blue" );
$b2 = new Ball ( "Red" );
echo "Ball 1's color: ".$b1->getColor();
echo "<br>Ball 2's color: ".$b2->getColor();Hope that was a little bit helpful