what is this thing: ->

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
batcloud
Forum Newbie
Posts: 15
Joined: Sun Jun 10, 2007 3:04 pm

what is this thing: ->

Post by batcloud »

Dumb question:
There is a piece of code that I want to modify. But I keep coming across the operator ->
What is it? Google search does not return anything sensible, probably because it ignores those characters. Same with devNet searches, php dot net. I am sure it is a simple thing, but I don't know php. Is it some kind of value assignment? Or is it passing values?
For example in:
return $this->data['title'];
what is the operator that comes after $this
Thanks
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

The "->" operator (in PHP) is how you access an object's functions and attributes.

Code: Select all

$result = mysql_query($query);
$object = mysql_fetch_object($result);

echo $object->data;

Using it with the $this keyword implies that you are working within a class.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

If you search my posts for threads where I said "deref*" you'll find answers. :)
batcloud
Forum Newbie
Posts: 15
Joined: Sun Jun 10, 2007 3:04 pm

Post by batcloud »

Summary of what I found:

T_OBJECT_OPERATOR is a parser token whose syntax is ->
Pronounced "deref", short for dereference.
More information may be available where ever classes and objects are discussed.

Thanks feyd, superdezign, timvw !
Post Reply