Forum Moderators: coopster

Message Too Old, No Replies

sign ->

         

ayushchd

7:11 pm on Aug 10, 2007 (gmt 0)

10+ Year Member



can anyone tell me wht is the use of this( -> ) sign in php?

PHP_Chimp

7:15 pm on Aug 10, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



its used within class's.
Have a look at
[uk.php.net...]
and
[uk.php.net...]

WesleyC

7:22 pm on Aug 10, 2007 (gmt 0)

10+ Year Member



It's a class reference.

A class is an "object" that can contain "methods" (basically functions with some special properties) and "properties" (basically variables, but contained within the class so that they don't override variable names.

For instance...

//class built for PHP 4
class Dog
{

var $hairColor;
var $hairLength;

function Dog($hairColor, $hairLength)
{
$this->hairColor = $hairColor;
$this->hairLength = $hairLength;
}

}

In your code, to create a new Dog, you would then use...

$dog1 = new Dog("brown", "1 inch");
$dog2 = new Dog("black", "1 inch");

//Uh-oh, dog 2's hair grew.
$dog2->hairLength = "2 inches";
//dog 1 got much older and his hair turned white...
$dog1->hairColor = "white";

[edited by: WesleyC at 7:23 pm (utc) on Aug. 10, 2007]