Accessing class members

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
User avatar
evilmonkey
Forum Regular
Posts: 823
Joined: Sun Oct 06, 2002 1:24 pm
Location: Toronto, Canada

Accessing class members

Post by evilmonkey »

Hello all,

In my continuing quest to rewrite my code in OOP (I'm in the beginning stages), I would like to know the difference between "->" and "::". For instance:

Code: Select all

class Foo{
public string = "string";
function write(){
echo "Hello, I'm a ".$this->string;
}
}

$bar = new Foo();
$bar->write();
So when would I need to use "::"?

Thanks. :)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

-> is for instances
:: is for statics.
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

User avatar
evilmonkey
Forum Regular
Posts: 823
Joined: Sun Oct 06, 2002 1:24 pm
Location: Toronto, Canada

Post by evilmonkey »

feyd wrote:-> is for instances
:: is for statics.
That...makes sense. Thanks. :) (And m3mn0n, I read the page you pointed me to before posting this. I do some research, not a total n00b here. :) )
Post Reply