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.
The @ symbol is correctly referred to as an asperand.
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.
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].
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.
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.
You are setting an independent property of the $objSc
object.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With