PHP 5 introduces the magic method __get() and __set(). From my understanding it is a shortcut for having to write each member's getter and setter;
<?php
class Person {
private $firstname;
private $lastname;
function __set($var, $name) {
$this->$var = $name;
}
function __get($var) {
return $this->$var;
}
}
$person = new Person();
$person->firstname = "Tom";
$person->lastname = "Brady";
echo $person->firstname . " " . $person->lastname;
// print: Tom Brady
?>
My question is, this is just like making the member variables public.
class Person {
public $firstname;
public $lastname;
}
Isn't this against OOP principles? And what's the point?