class Person { public function __get($prop) { return "unknown"; } } $person = new Person(); echo $person->age; // output: unknown
class User { protected $id = 123; public function __get($prop) { if ($prop == "id") { return $this->$prop; } } } $user = new User(); echo $user->id; // output: 123Both of these code examples belong to the PHP package library.