On Sun, Mar 15, 2020, at 4:44 PM, Máté Kocsis wrote:
> >
> > Avoiding that confusion will save the industry millions of dollars.
> >
> 
> On the one hand, you are right, because currently it's not very useful to
> effectively provide two
> ways of declaring a constant. On the other hand however, if we also
> consider a longer term
> aim of adding support for object default values (just like what Marco
> mentioned):
> public read-only DateTimeImmutable $startupTime = new DateTimeImmutable();
> then allowing default values for "write-once" properties seems much more
> sensible. At this point,
> the "million dollar mistake" label doesn't hold anymore since class
> constants and "write-once"
> properties with default values will actually be two different things. But
> we've just ended up at
> Marco's suggestion:

I'll be honest, I really have no idea how default object values is at all 
related here.  I mean, those would be nice to have as well for various reasons, 
but I don't see how it's related to read-only properties.

> >  1. Prevent the parser from accepting default values on write-once
> > properties (parser error)
> >  2. Re-introduce them once we know what we want to do with default values
> > (and it makes sense)
> 
> Yes, this scenario definitely makes sense. I'm just not yet sold that it
> will have any negative effects
> if we don't restrict the usage of default values now. I understand that
> it's usually advantageous to be
> conservative with adding new features - especially when groping in the dark
> - since we are the ones
> who have to support and fix them later. That's why I was hesitant to add
> property covariance to the
> proposal.

The negative effect is if we later decide that it's too much of a problem to 
have default values, because they're just too confusing (people debating if 
they should be a constant, people expecting them to be overwriteable, etc.), we 
can't simply remove them.  That would be a large breaking change and not 
allowed, so we're stuck with 'em.

Whereas if we don't add it now, we can see if people are really clammoring for 
it and in what situations.  We let the PHP-using masses do the research for us 
to determine how read-only-default would actually be useful, or if it would be 
useful at all.  Then we can add it later in a way that would actually be 
useful, or decide not to do it at all.

--Larry Garfield

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

Reply via email to