Jump to content

Archived

This topic is now archived and is closed to further replies.

bishup

Simple question - just wondering

Recommended Posts

When variables are being declaired and manipulated I am running in to this structure of code.

$this->variable_name = 'homey the clown';
(ex.)

What is the $this used for and what does it do, i have no clue...



Might as well through this out there also, what is...

$this->variable .= 'something to have';


Appreachiate the help / insight

Share this post


Link to post
Share on other sites
$this is a keyword within a class that refers to the classes global variables.

$this->variable_name = "x"; will set the class's variable equal to x.

The .= is an append. It will add whatever is past the equals sign to the current string instead of replacing it.

Share this post


Link to post
Share on other sites
[!--quoteo(post=371289:date=May 4 2006, 11:28 AM:name=ober)--][div class=\'quotetop\']QUOTE(ober @ May 4 2006, 11:28 AM) [snapback]371289[/snapback][/div][div class=\'quotemain\'][!--quotec--]
$this is a keyword within a class that refers to the classes global variables.

$this->variable_name = "x"; will set the class's variable equal to x.

The .= is an append. It will add whatever is past the equals sign to the current string instead of replacing it.
[/quote]


Thank you, that is what i needed to know!

that make a lot more sence when i read through other code.

Share this post


Link to post
Share on other sites
Also note that $this-> is used to call internal functions within the class too aswell as variables. Example:[code]<?php

class foo {

    function foo() {
        //call bar();
        $this->bar();
    }

    function bar() {
        echo "bar() was called internally!";
    }

}

$foo = new foo;

?>[/code]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.