@ebrahemsamer They are Magic Methods
__set() is run when writing data to inaccessible (protected or private) or non-existing properties.
__get() is utilized for reading data from inaccessible (protected or private) or non-existing properties.
__isset() is triggered by calling isset() or empty() on inaccessible (protected or private) or non-existing properties.
__unset() is invoked when unset() is used on inaccessible (protected or private) or non-existing properties.
More information you can find here.
class User {
private $Id;
private $username;
public function __get($property)
{
if (property_exists($this, $property)) {
return $this->$property;
}
}
public function __set($property, $value)
{
if (property_exists($this, $property)) {
$this->$property = $value;
}
return $this;
}
}