Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What do we call this?

Tags:

php

naming

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.

like image 628
shinkou Avatar asked May 27 '10 08:05

shinkou


People also ask

What is the at symbol called?

The @ symbol is correctly referred to as an asperand.

What are these punctuation marks called?

What are the 14 Punctuation Marks in English? There are 14 punctuation marks that are used in the English language. They are: the period, question mark, exclamation point, comma, colon, semicolon, dash, hyphen, brackets, braces, parentheses, apostrophe, quotation mark, and ellipsis.

What is the email symbol called?

On the Internet, @ (pronounced "at" or "at sign" or "address sign") is the symbol in an E-mail address that separates the name of the user from the user's Internet address, as in this hypothetical e-mail address example: [email protected].


3 Answers

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.

like image 173
Marc Ripley Avatar answered Oct 14 '22 01:10

Marc Ripley


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.

like image 27
Sarfraz Avatar answered Oct 14 '22 01:10

Sarfraz


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

like image 30
Delan Azabani Avatar answered Oct 14 '22 02:10

Delan Azabani