On 29/06/2020 17:21, Marco Pivetta wrote:
Hey Rowan,

On Mon, Jun 29, 2020, 18:19 Rowan Tommins <rowan.coll...@gmail.com <mailto:rowan.coll...@gmail.com>> wrote:

    On Mon, 29 Jun 2020 at 16:44, Marco Pivetta <ocram...@gmail.com
    <mailto:ocram...@gmail.com>> wrote:

    > property accessors seem to perpetuate the bad practice
    > of getters and setters
    >


    Outside 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 👍


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 {
    private string $_name;
    public string $name {
         get {
             if( ! isset($_name) ) { $this->loadData(); }
             return $this->_name;
         }
    }
}


Regards,

--
Rowan Tommins (né Collins)
[IMSoP]

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php

Reply via email to