I'm developing an application in PHP. I am trying to figure out the use of $this-> and why it is always preferred.
I mean we can simply echo a property value inside a method using this code
<?php
class place{
public $country;
public function countryName($country){
echo $country;
}
}
$info = new place();
$info->countryName("Nepal");
?>
But, in examples I see that $this-> is used in this way:
<?php
class place{
public $country;
public function countryName($country){
$this->country = $country;
echo $this->country;
}
}
$info = new place();
$info->countryName("Nepal");
?>
Is the use of $this-> preferred or is the first method totally normal?