What does -> mean in a class or OOP?
Moderator: General Moderators
-
yuejdesigner85
- Forum Newbie
- Posts: 4
- Joined: Mon Dec 04, 2006 12:45 pm
What does -> mean in a class or OOP?
I know it's an arrow pointing at a variable, but what does it mean when it points to a variable?
Might want to start here
http://us2.php.net/manual/en/language.oop5.php
and then maybe here:
http://www.zend.com/php5/articles/engine2-php-oo.php
http://us2.php.net/manual/en/language.oop5.php
and then maybe here:
http://www.zend.com/php5/articles/engine2-php-oo.php
-
yuejdesigner85
- Forum Newbie
- Posts: 4
- Joined: Mon Dec 04, 2006 12:45 pm
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
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...
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...
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
?>PS | This has nothing to do with arrays or keys/values incidentally.
PPS | Just for nostalgic reasons...
-
yuejdesigner85
- Forum Newbie
- Posts: 4
- Joined: Mon Dec 04, 2006 12:45 pm
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
Code: Select all
var parent = element.parentNode;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
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
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
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.
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.
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
yuejdesigner85 wrote:i still don really know what it does, if anyone don't mind, please explain it to me, thanks a lot!
I would say the easiest explanation of the object operator is that is allows access to the parts of the object. Basically you are sayingEverah 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 ?>
. Sorry for not being able to explain it better. I hope this helps in some capacity.Object ($object), go get (->) this variable (property)