Page 1 of 1
What does -> mean in a class or OOP?
Posted: Mon Dec 04, 2006 12:47 pm
by yuejdesigner85
I know it's an arrow pointing at a variable, but what does it mean when it points to a variable?
Posted: Mon Dec 04, 2006 12:55 pm
by Luke
Posted: Mon Dec 04, 2006 12:56 pm
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.
Posted: Mon Dec 04, 2006 1:01 pm
by feyd
Posted: Mon Dec 04, 2006 1:51 pm
by yuejdesigner85
which one is the key and which one is the value?
$key->$value
or
$this->$key = $value
Posted: Mon Dec 04, 2006 2:06 pm
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...
Posted: Mon Dec 04, 2006 4:43 pm
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.
Posted: Tue Dec 05, 2006 1:00 pm
by yuejdesigner85
i still don really know what it does, if anyone don't mind, please explain it to me, thanks a lot!
Posted: Tue Dec 05, 2006 1:15 pm
by Luke
It doesn't really
do anything... are you familiar with java syntax at all or even javascript? syntax like this...
-> 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
Posted: Tue Dec 05, 2006 2:31 pm
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.
OOP
Posted: Tue Dec 05, 2006 3:41 pm
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.
Posted: Wed Dec 06, 2006 11:01 am
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.