Jump to content


Photo

Simple question - just wondering


  • Please log in to reply
3 replies to this topic

#1 bishup

bishup
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 04 May 2006 - 03:17 PM

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

#2 ober

ober
  • Staff Alumni
  • Advanced Member
  • 5,337 posts
  • LocationEast Coast, USA

Posted 04 May 2006 - 03:28 PM

$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.

Info: PHP Manual


#3 bishup

bishup
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 04 May 2006 - 03:53 PM

[!--quoteo(post=371289:date=May 4 2006, 11:28 AM:name=ober)--][div class=\'quotetop\']QUOTE(ober @ May 4 2006, 11:28 AM) View Post[/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.

#4 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 04 May 2006 - 04:25 PM

Also note that $this-> is used to call internal functions within the class too aswell as variables. Example:
<?php

class foo {

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

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

}

$foo = new foo;

?>





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users