Re: [RFC] [VOTE] Typed properties v2
| From: | Rowan Collins | Date: | Wed, 19 Sep 2018 21:17:05 +0000 |
| Subject: | Re: [RFC] [VOTE] Typed properties v2 | ||
| References: | 1 2 3 4 5 6 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-103188@lists.php.net to get a copy of this message | ||
On 19/09/2018 21:04, Levi Morrison wrote:
I think this code should be allowed:
class User {
public int $id;
public string $preferred_name;
public string $username;
}
Why? What contract is being enforced by that class that is not enforced by this class?
class User {
public ?int $id=null;
public ?string $preferred_name=null;
public ?string $username=null;
}
Both require the consumer of the class to trust that someone, somewhere, has initialised the fields (and not subsequently unset them).
Or have I misunderstood what you intended with that example?
Regards,
--
Rowan Collins
[IMSoP]