Re: [PHP-DEV] [RFC] Property write visibility

2020-07-07 Thread Larry Garfield
On Tue, Jul 7, 2020, at 2:35 AM, André Rømcke wrote: > > > > ergonomic, and in the case of magic method usage improve performance. > >> > > > > I think this is a good direction to explore, but would recommend delaying > > it until PHP 8.1. As the RFC and discussion note, the design space here > > o

Re: [PHP-DEV] [RFC] Property write visibility

2020-07-07 Thread André Rømcke
> > ergonomic, and in the case of magic method usage improve performance. >> > > I think this is a good direction to explore, but would recommend delaying > it until PHP 8.1. As the RFC and discussion note, the design space here > overlaps significantly with both readonly/immutability and property

Re: [PHP-DEV] [RFC] Property write visibility

2020-07-07 Thread André Rømcke
> > I think the only thing worth mentioning where references are concerned is > that "$x =& $this->prop" is considered a write of $this->prop, not a read, > so it is subject to the write visibility. But once the reference is > acquired, visibility no longer factors into the behavior. > > Ok, thank

Re: [PHP-DEV] [RFC] Property write visibility

2020-07-01 Thread Nikita Popov
On Wed, Jul 1, 2020 at 12:58 PM André Rømcke wrote: > > "Attempting to pass a property value outside of allowed writable scope >> as a reference, results in an error." > > > ... we definitely shouldn't do this, because it goes against existing > language semantics. You can take a reference to a n

Re: [PHP-DEV] [RFC] Property write visibility

2020-07-01 Thread André Rømcke
>> "Attempting to pass a property value outside of allowed writable scope >> as a reference, results in an error." > > ... we definitely shouldn't do this, because it goes against existing > language semantics. You can take a reference to a normal private property > (i.e. private get, private s

Re: [PHP-DEV] [RFC] Property write visibility

2020-07-01 Thread Nikita Popov
On Tue, Jun 30, 2020 at 1:26 PM Dan Ackroyd wrote: > On Mon, 29 Jun 2020 at 10:42, André Rømcke wrote: > > > > I'd like to start discussion on a new RFC proposing a way to be able to > > (optionally) specify property > > write visibility, separate from read: > > > > https://wiki.php.net/rfc/prop

Re: [PHP-DEV] [RFC] Property write visibility

2020-06-30 Thread André Rømcke
> Perhaps another option could be to use attributes: > > <> > public int $id; I’d actually also like a syntax like that as well for ReadOnly and Immutable in the end. It's more readable and it would be possible to annotate on the class level as well (to affect all properties). So I initially e

Re: [PHP-DEV] [RFC] Property write visibility

2020-06-30 Thread Dan Ackroyd
On Mon, 29 Jun 2020 at 10:42, André Rømcke wrote: > > I'd like to start discussion on a new RFC proposing a way to be able to > (optionally) specify property > write visibility, separate from read: > > https://wiki.php.net/rfc/property_write_visibility > >From the RFC: "Attempting to pass a prope

Re: [PHP-DEV] [RFC] Property write visibility

2020-06-30 Thread Nikita Popov
On Mon, Jun 29, 2020 at 11:43 AM André Rømcke wrote: > Good morning Internals, > > I'd like to start discussion on a new RFC proposing a way to be able to > (optionally) specify property > write visibility, separate from read: > > https://wiki.php.net/rfc/property_write_visibility > > This enable

Re: [PHP-DEV] [RFC] Property write visibility

2020-06-30 Thread someniatko
I do agree with Marco that this is a step in a wrong direction. Our goal should be not ensuring that a prop is not rewritten outside, but rather that it is not re-written at all. It makes no sense to rewrite a property in majority of cases: 1. fields of an DTO - nay. Should be immutable instead. Yo

Re: [PHP-DEV] [RFC] Property write visibility

2020-06-29 Thread Dik Takken
On 29-06-2020 11:41, André Rømcke wrote: > Good morning Internals, > > I'd like to start discussion on a new RFC proposing a way to be able to > (optionally) specify property > write visibility, separate from read: > > https://wiki.php.net/rfc/property_write_visibility Perhaps another option cou

Re: [PHP-DEV] [RFC] Property write visibility

2020-06-29 Thread Larry Garfield
On Mon, Jun 29, 2020, at 10:16 AM, David Rodrigues wrote: > With all possibilities maybe we have: > > - public set:private unset:private isset:private get:private > > set:private could be readed like "set is private". > > Where: > > - public is "general visibility" for set, unset, isset and get

Re: [PHP-DEV] [RFC] Property write visibility

2020-06-29 Thread Rowan Tommins
On 29/06/2020 17:21, Marco Pivetta wrote: Hey Rowan, On Mon, Jun 29, 2020, 18:19 Rowan Tommins > wrote: On Mon, 29 Jun 2020 at 16:44, Marco Pivetta mailto:ocram...@gmail.com>> wrote: > property accessors seem to perpetuate the bad practice > of gett

Re: [PHP-DEV] [RFC] Property write visibility

2020-06-29 Thread Nicolas Grekas
> > I'd like to start discussion on a new RFC proposing a way to be able to > (optionally) specify property > write visibility, separate from read: > > https://wiki.php.net/rfc/property_write_visibility > > This enables readonly, write-only and immutable like semantics for PHP's > properties. > > T

Re: [PHP-DEV] [RFC] Property write visibility

2020-06-29 Thread Marco Pivetta
Hey Rowan, On Mon, Jun 29, 2020, 18:19 Rowan Tommins wrote: > On Mon, 29 Jun 2020 at 16:44, Marco Pivetta 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

Re: [PHP-DEV] [RFC] Property write visibility

2020-06-29 Thread Rowan Tommins
On Mon, 29 Jun 2020 at 16:44, Marco Pivetta 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. > Máté a

Re: [PHP-DEV] [RFC] Property write visibility

2020-06-29 Thread Marco Pivetta
Hey André, This does indeed seem to cut into the traditional property accessors scope. I'm no longer seeing a reason to have property accessors, since immutable state (and promotion thereof) is much more relevant to fight bugs and improve application performance and maintainability. Therefore, I

Re: [PHP-DEV] [RFC] Property write visibility

2020-06-29 Thread David Rodrigues
With all possibilities maybe we have: - public set:private unset:private isset:private get:private set:private could be readed like "set is private". Where: - public is "general visibility" for set, unset, isset and get; - set: affects write visibility; - unset: affects unset() visibility; - is

Re: [PHP-DEV] [RFC] Property write visibility

2020-06-29 Thread Deleu
As a user, I would prefer the original proposed syntax `public:private` or the Swift syntax `public private(set)` than the alternative syntax `public int $x {protected set; protected unset;}`. On Mon, Jun 29, 2020 at 4:22 PM Mark Randall wrote: > On 29/06/2020 15:13, André Rømcke wrote: > > Woul

Re: [PHP-DEV] [RFC] Property write visibility

2020-06-29 Thread Mark Randall
On 29/06/2020 15:13, André Rømcke wrote: Would something closer to Swift be better? If so I expanded the RFC with that syntax option as well: Borrowing from the various accessors RFCs: public int $x { protected set; protected unset; } Then a future RFC can build upon it by adding the over

Re: [PHP-DEV] [RFC] Property write visibility

2020-06-29 Thread André Rømcke
> > >> I agree that there is a use case for it, however I don't think the > proposed syntax `public:private` is intuitive. Maybe we can come up with > something better? > Would something closer to Swift be better? If so I expanded the RFC with that syntax option as well: class User { public p

Re: [PHP-DEV] [RFC] Property write visibility

2020-06-29 Thread André Rømcke
man. 29. jun. 2020 kl. 12:06 skrev Deleu : > Are there any other languages that have a similar syntax? Has any other language syntax been considered The only one I could find that matches is Swift: public private(set) var numberOfEdits = 0 https://docs.swift.org/swift-book/LanguageGuide/AccessCo

Re: [PHP-DEV] [RFC] Property write visibility

2020-06-29 Thread Deleu
I don't dislike the syntax and I think I can get used to it extremely fast, tbh. Are there any other languages that have a similar syntax? Has any other language syntax been considered? On Mon, Jun 29, 2020 at 12:01 PM Max Semenik wrote: > On Mon, Jun 29, 2020 at 12:42 PM André Rømcke > wrote:

Re: [PHP-DEV] [RFC] Property write visibility

2020-06-29 Thread Max Semenik
On Mon, Jun 29, 2020 at 12:42 PM André Rømcke wrote: > This enables readonly, write-only and immutable like semantics for PHP's > properties. > I agree that there is a use case for it, however I don't think the proposed syntax `public:private` is intuitive. Maybe we can come up with something be

[PHP-DEV] [RFC] Property write visibility

2020-06-29 Thread André Rømcke
Good morning Internals, I'd like to start discussion on a new RFC proposing a way to be able to (optionally) specify property write visibility, separate from read: https://wiki.php.net/rfc/property_write_visibility This enables readonly, write-only and immutable like semantics for PHP's properti