Re: [RFC] Property write visibility
| From: | Rowan Tommins | Date: | Mon, 29 Jun 2020 17:58:51 +0000 |
| Subject: | Re: [RFC] Property write visibility | ||
| References: | 1 2 3 4 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-110787@lists.php.net to get a copy of this message | ||
On 29/06/2020 17:21, Marco Pivetta wrote:
Hey Rowan, On Mon, Jun 29, 2020, 18:19 Rowan Tommins <rowan.collins@gmail.com <mailto:rowan.collins@gmail.com>> wrote:I meant that property accessors can be used to implement lazy-loading, removing the need for magic methods and dynamic references to variables, e.g.: class Whatever {On Mon, 29 Jun 2020 at 16:44, Marco Pivetta <ocramius@gmail.com <mailto:ocramius@gmail.com>> wrote:property accessors seem to perpetuate the bad practice of getters and settersOutside of access restrictions, a common use case I've seen for property accessors is lazy-loading, which I know is something you use in other forms.I had already tested the write-once properties RFC with lazy-loading: works just fine 👍
private string $_name;
public string $name {
get {
if( ! isset($_name) ) { $this->loadData(); }
return $this->_name;
}
}
}
Regards,
--
Rowan Tommins (né Collins)
[IMSoP]