Forum Moderators: coopster

Message Too Old, No Replies

What is ->?

         

lewby

6:12 pm on Mar 8, 2007 (gmt 0)

10+ Year Member



Hi.

This may seem like a stupid question, but what is -> and what does it do? i see it in many pre-written scripts however have never come accross it in a tuorial. im hoping someone could she a light.

benevolent001

6:21 pm on Mar 8, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Are you pointing to comments sort of thing?

cameraman

7:15 pm on Mar 8, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It's used to access member functions and variables of a class:
class foo {
var $a;
function bar() {
echo "bar";
} // end bar()
} // end class

$object = new foo();
$object2 = new foo();

$object -> bar(); // executes the function, outputs 'bar'
$object -> a = "hi ";
$object2 -> a = "there";

echo $object->a . $object2->a; // Outputs 'hi there'

lewby

7:25 pm on Mar 8, 2007 (gmt 0)

10+ Year Member



Ah gotcha. Thanks very much.

eelixduppy

8:10 pm on Mar 8, 2007 (gmt 0)



If my memory serves me correctly, I believe it's called the arrow membership operator. :)

phranque

1:02 am on Mar 9, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



the arrow operator is actually an infix dereference operator.
generally the left side is a reference or something could be made into a reference and the right side is some method of addressing a resource in that reference.