class User {
public $name;
public function __construct($name) {
$this->name = $name;
}
public function sayHi() {
echo "Hi, I am $this->name!";
}
}
Can someone explain to me word by word, what is meant by $this->name=$name? I keep thinking like, $this goes into(hence the -> sign) name which is (hence the = sign) $name defined beforehand. Also I dont see the need of that function?
Could just go like this :
class User {
public $name;
public function sayHi() {
echo "Hi, I am $name!";
}
}
I'm out of idea thinking about this .. thanks in advance.