<?php class User { public string $first_name; public string $last_name; /** * this is going to be a lazy property, uninitialized by default, perhaps writting like: * * lazy public string $full_name; */ public string $full_name; function __construct() { // this is what the "lazy" type would do in the background.. keep the public property uninitialized until set otherwise handled by __get/__set unset($this->full_name); } function __get($key) { if ($key === 'full_name') { return $this->first_name.' '.$this->last_name; } } } $user = new User(); $user->first_name = 'John'; $user->last_name = 'Wick'; echo $user->full_name;
You have javascript disabled. You will not be able to edit any code.