Jump to content

Simple question - just wondering


bishup

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
Link to comment
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.
Link to comment
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.
Link to comment
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]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.