Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 10-27-2008, 09:48 PM how does -> work
Average Talker

Posts: 17
Name: Gregor Mesec
Trades: 0
Hello all

i've been in to php for about a year now, and something is still buging me, i can not find any explanation on the net as how does asigning variables with -> work. i obviously cant search google as -> does not return any results that would help me.

i can code everything without that, but i would still like to know where can it be used, and how...

thank you
mesec is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 10-27-2008, 10:09 PM Re: how does -> work
Experienced Talker

Posts: 41
Name: Jabis Sevon
Location: Tampere, Finland
Trades: 0
Check out classes and the PHP OO Pattern to get a grasp of them
jabis is offline
Reply With Quote
View Public Profile Visit jabis's homepage!
 
Old 10-27-2008, 11:23 PM Re: how does -> work
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
-> works the same as . in java and c++. Say you have a class foo and within that class you have a method bar, you would have to use the -> operator to access that method.
PHP Code:
<?php
class Foo
{
    function 
bar()
    {
       echo 
'foobar';
    }
}

$foo = new Foo;
$x->bar();
?>
You also use -> to access any public member variables of a class.

EDIT:
Whenever I edit code I've posted I keep getting asterisks inserted that I cannot remove for some reason. Anyone else have this problem?
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

Last edited by vangogh; 10-28-2008 at 07:58 PM..
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 10-28-2008, 07:58 PM Re: how does -> work
vangogh's Avatar
Post Impressionist

Latest Blog Post:
Why Responsive Design?
Posts: 10,815
Name: Steven Bradley
Location: Boulder, Colorado
Trades: 0
Matt I took out the asterisks and replaced them with spaces. I'm guessing your code was tabbed and I guess that somehow gets turned into asterisks. I think only spaces will work, but don't hold me to that.
__________________
l Search Engine Friendly Web Design |
Please login or register to view this content. Registration is FREE

l Tips On Marketing, SEO, Design, and Development |
Please login or register to view this content. Registration is FREE

l
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
vangogh is offline
Reply With Quote
View Public Profile Visit vangogh's homepage!
 
Old 10-28-2008, 08:10 PM Re: how does -> work
Average Talker

Posts: 17
Name: Gregor Mesec
Trades: 0
thank you very much, you've both been very helpfull, i come from a computer science school so object oriented programing is not new to me, but never got into using it with php... so once more, thank you for pointing me in the right direction

btw, i'd like to say that my life has gotten a whole lot easier and more fun since two days ago when i discovered this forum
mesec is offline
Reply With Quote
View Public Profile
 
Old 10-28-2008, 08:14 PM Re: how does -> work
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,918
Name: Keith Marshall
Location: Connecticut
Trades: 0
To tag onto what Matt said - the -> is identifying the method (a.k.a. function) or var (a.k.a. variable) of an object (a.k.a. class).

The -> identifier can be replaced with ::
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Old 10-29-2008, 03:38 PM Re: how does -> work
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
I was never comfortable using :: in place of -> in php. In c++ :: is used for scoping (identifying a namespace). I read that when php 6 is released \ will be the operator for namespaces so that will be even more confusing for me.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Reply     « Reply to how does -> work
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.61983 seconds with 12 queries