Page 1 of 1

How do I concatenate to a class variable

Posted: Sun Jul 09, 2006 3:40 pm
by Benjamin
I am assuming this is very simple but I couldn't find it in the manual..

if I have a code peice like this...

Code: Select all

$this->variablename = 'blah';
besides doing this..

Code: Select all

$this->variablename = $this->variablename .= 'blah';
Is there a shortcut for concating to it? Also is this what is called instantiate?

Thanks.

Posted: Sun Jul 09, 2006 3:48 pm
by Oren
I think you meant something like this:

Code: Select all

$this->variablename .= 'blah';
Is that what you meant?

Posted: Sun Jul 09, 2006 3:55 pm
by Benjamin
Yeah think so :oops:

Posted: Sun Jul 09, 2006 4:13 pm
by Oren
So, was that the answer for your question?

Re: How do I concatenate to a class variable

Posted: Sun Jul 09, 2006 5:45 pm
by bdlang
astions wrote:

Code: Select all

$this->variablename = $this->variablename .= 'blah';
Is there a shortcut for concating to it?
You've basically done it, just do

Code: Select all

$this->variablename .= 'blah';
Literally means

Code: Select all

$this->variablename = $this->variablename . 'blah';
Also is this what is called instantiate?
To 'instantiate' your class is to create an object instance of the class, e.g.

Code: Select all

class Foo
{
    private $data;
    public function __construct() {
        $this->data = 'Foo';
    }
    public function getData() {
        return $this->data;
    }
}

// instantiate an object
$newFooObject= new Foo();
// the object $newFooObject is an instance of the class 'Foo'

// use the new instance to 'do something'
echo $newFooObject->getData();

I suggest reading some fundamentals about Classes and Objects in PHP 4 and then once you have a basic understanding, read about them in PHP 5. Also note you're not restricted to learning about objects in PHP alone, there are volumes out there on the subject.

Posted: Sun Jul 09, 2006 7:09 pm
by Benjamin
Thank you, that answers all my questions. I understand the fundamentals, just not the terminology.