Page 1 of 1
objects and classes
Posted: Tue Apr 26, 2005 6:03 am
by shiznatix
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?
Posted: Tue Apr 26, 2005 6:30 am
by Skittlewidth
"$this" is an instance of an object and "->" allows you to access properties, methods etc of that object class. So "something" could be an object method or variable.
Posted: Tue Apr 26, 2005 5:49 pm
by Todd_Z
I'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:
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();
"$this->" is used within the ball, to refer to the object's own variables.
Hope that was a little bit helpful
