What does -> mean in a class or OOP?

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
yuejdesigner85
Forum Newbie
Posts: 4
Joined: Mon Dec 04, 2006 12:45 pm

What does -> mean in a class or OOP?

Post by yuejdesigner85 »

I know it's an arrow pointing at a variable, but what does it mean when it points to a variable?
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

impulse()
Forum Regular
Posts: 748
Joined: Wed Aug 09, 2006 8:36 am
Location: Staffordshire, UK
Contact:

Post by impulse() »

As far as I know the part attached and before the arrow is the class name and the latter part is the name of the variable within the class.

Hope that helps, Ste.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

yuejdesigner85
Forum Newbie
Posts: 4
Joined: Mon Dec 04, 2006 12:45 pm

Post by yuejdesigner85 »

which one is the key and which one is the value?
$key->$value
or
$this->$key = $value
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

I have heard it called different things, but the one that makes the most sense is 'the object operator'. I actually asked this question when I first got to these boards. The syntax for using the object operator is...

Code: Select all

<?php
$object_var = new Class_Name_To_Objectify();
$object_var->method(); // A method is another way to describe a class function
$object_var->property; // A property is another way to describe a class variable
?>
Notice the way you access parts of the object using the object operator?

PS | This has nothing to do with arrays or keys/values incidentally.

PPS | Just for nostalgic reasons...
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

yuejdesigner85 wrote:which one is the key and which one is the value?
$key->$value
or
$this->$key = $value
Neither. Keys and values are in arrays. Classes have objects/instances and properties/members/methods.
yuejdesigner85
Forum Newbie
Posts: 4
Joined: Mon Dec 04, 2006 12:45 pm

Post by yuejdesigner85 »

i still don really know what it does, if anyone don't mind, please explain it to me, thanks a lot!
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

It doesn't really do anything... are you familiar with java syntax at all or even javascript? syntax like this...

Code: Select all

var parent = element.parentNode;
-> is to php what . is to java(script).

You need to look at an object-oriented php (or any oop language really) tutorial before you'll truly understand.

http://www.google.com/search?hl=en&lr=& ... tnG=Search
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

In C++ it actually does do something: dereferences. It is nothing more than a language construct to get into the internals of an object. C based languages will use the arrow most often, while Java styled languages will use the dot operator. There are other constructs in other languages, but it doesn't really matter here. Their idea is the same, access the internal properties and methods of an object instance.
timclaason
Forum Commoner
Posts: 77
Joined: Tue Dec 16, 2003 9:06 am
Location: WI

OOP

Post by timclaason »

OOP is really a paradigm as much as it is anything else. It's a different way of programming, breaking things down into simpler form.

There's a great Java OOP tutorial at http://sepwww.stanford.edu/sep/josman/oop/oop1.htm

I know PHP is not Java, but I think that page does a really great job at describing OOP in a simple, fun way. And OOP is OOP. If you understand OOP in Java, you'll understand it in PHP. Granted, PHP does not have as much OOP capabilities as Java, but the above tutorial is good.

Check it out...it's worth a read.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

yuejdesigner85 wrote:i still don really know what it does, if anyone don't mind, please explain it to me, thanks a lot!
Everah wrote:

Code: Select all

<?php
// Instantiate a new object of the class Class_Name_To_Objectify
$object_var = new Class_Name_To_Objectify();

// Access the method() function [method] of the class [object]
$object_var->method(); // A method is another way to describe a class function

// Access the variable 'property' [which is a property] of the class [object]
$object_var->property; // A property is another way to describe a class variable
?>
I would say the easiest explanation of the object operator is that is allows access to the parts of the object. Basically you are saying
Object ($object), go get (->) this variable (property)
. Sorry for not being able to explain it better. I hope this helps in some capacity.
Post Reply