Re: [RFC] [VOTE] Typed properties v2
| From: | Levi Morrison | Date: | Thu, 20 Sep 2018 14:50:30 +0000 |
| Subject: | Re: [RFC] [VOTE] Typed properties v2 | ||
| References: | 1 2 3 4 5 6 7 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-103205@lists.php.net to get a copy of this message | ||
This will be my last reply to this thread. Fundamentally:
class User {
public ?int $id;
public ?string $preferred_name;
public ?string $username;
}
^ This permits null properties at all times. This is acceptable
behavior if null is valid for the domain. It is not valid for this
domain -- all 3 are required.
class User {
public int $id;
public string $preferred_name;
public string $username;
}
^ This never permits null properties, and using them without
initializing them is an error, and you get notified by the runtime
that such a thing happened. This is good and desirable behavior.