So, I tried learning PHP and I don't understand the use of $this keyword. I know that it is a pre-defined keyword and it is in-built reference to class. But what does it mean here.
<!DOCTYPE html>
<html>
<body>
<?php
class Fruit {
public $name;
// Methods
function set_name($name) {
$this->name = $name;
}
function get_name() {
return $this->name;
}
}
$apple = new Fruit();
$banana = new Fruit();
$apple->set_name('Apple');
echo $apple->get_name();
?>
</body>
</html>
specifically here
function set_name($name) { $this->name = $name; }
and
function get_name() { return $this->name; }
can't we just store the name in $name then just use it to return the name in get_name method