tags:

views:

87

answers:

3

I'm wondering what do we call this kind of assignment.

<?php
class SimpleClass
{
    public $var1;
    public $var2;
    public $var3;

    public function SimpleClass()
    {
        $this->var1 = 'one';
        $this->var2 = 'two';
        $this->var3 = 'three';
    }
}

function test()
{
    $objSc = new SimpleClass();
    $objSc->var4 = 'WTF?!'; # <-- what do we call this?
    var_dump($objSc);
}

test();
?>

Better with references or links. Thanks in advance!

EDIT: I'm looking for a technical term for it... well, if we have.

+1  A: 

You are setting an independent property of the $objSc object.

Delan Azabani
+2  A: 

It is assigning the string WTF?! to a public scope variable of SimpleClass. If you var_dump it, it shows the output correctly as:

string(5) "WTF?!"

And as @marcdev pointed out, it is known as overloading.

Sarfraz
+9  A: 

I believe this is overloading.

Overloading in PHP provides means to dynamically "create" properties and methods. These dynamic entities are processed via magic methods one can establish in a class for various action types.

The overloading methods are invoked when interacting with properties or methods that have not been declared or are not visible in the current scope.

PHP Manual reference here.

Marc Ripley
The call to set the `var4` property of the `$objSc` object goes via the __set() magic method which you can set yourself to do other things too.
Blair McMillan
+1 for quoting the manual.
mizipzor