I am lead to believe by a book I am reading:
"It's easy to get confused between -> and => as well as when you need a $ and when you don't.
The class construction uses a dash with the greater than sign, and constructions working with associative arrays use the equal sign with the greater than sign.
The associative array used the normal form for the second variable, so it has a $ sign in front of the second variable.
There is normally no $ following $this->. You can think of the $ as meaning "use the value of what is inside." If you want to use the property $contacts, it is $this->contacts. You use the $ only if you want to use the value of what is in a property as the name of another property. The following two echo statements both display "george smith":
Is this just wrong? No matter what I try I can't see to get this to work in the way it is described in the book.
Here is what I currently have to demonstrate this:
The results of my code produce nothing at all.
"It's easy to get confused between -> and => as well as when you need a $ and when you don't.
The class construction uses a dash with the greater than sign, and constructions working with associative arrays use the equal sign with the greater than sign.
The associative array used the normal form for the second variable, so it has a $ sign in front of the second variable.
There is normally no $ following $this->. You can think of the $ as meaning "use the value of what is inside." If you want to use the property $contacts, it is $this->contacts. You use the $ only if you want to use the value of what is in a property as the name of another property. The following two echo statements both display "george smith":
PHP:
$this->field = "contacts;
$this->contacts = "george smith";
echo $this->$field;
echo $this->contact
Is this just wrong? No matter what I try I can't see to get this to work in the way it is described in the book.
Here is what I currently have to demonstrate this:
PHP:
<?php
class rar
{
public $field;
public $contact;
public function printThis()
{
$this->field = 'contact';
$this->contact = 'George Smith';
echo $this->$field;
echo $this->contact;
}
}
$thing = new rar();
$thing->printThis();
?>
The results of my code produce nothing at all.