Re: [RFC] Return Type Declarations pre-vote follow-up

From: Date: Fri, 09 May 2014 21:37:55 +0000
Subject: Re: [RFC] Return Type Declarations pre-vote follow-up
References: 1 2 3 4  Groups: php.internals 
Request: Send a blank email to [email protected] to get a copy of this message
On Fri, May 9, 2014 at 3:32 PM, Josh Watzman <[email protected]> wrote:

> > I'm not sure it is a good idea. This means having this code:
> > class FooGetter {
> >  function getFoo(): Foo { return new Foo(); }
> > }
> >
> > I can extend it as:
> > class TwoFaceFooGetter extends FooGetter {
> >  function getFoo() { return rand()%2?new Bar():new Foo(); }
> > }
> >
> > and every function getting FooGetter and expecting getFoo() to return
> > Foo is now broken since instead it could just get Bar(). Since the type
> > return specification is meant, as far as I understand, exactly to avoid
> > cases like that, I don't see it as a good idea.
>
> Our view is that this code was *already* wrong. The type annotations don't
> make it more or less wrong. What they do let you do is enforce, once the
> annotation is in place, that it's correct moving forward for the places
> that are annotated. (And if you want to go fix up and annotate
> TwoFaceFooGetter, go do that! Or if you don't right now, don't!) Doing it
> this way also means that you don't have to convert your entire hierarchy
> all at once -- gradual conversion of existing code was an important feature
> when we were adding the Hack type system onto PHP.


The behavior you are proposing is good for migration and adoption, but what
then? What about the years afterwards where you now have this ability to
break the return type? It's much harder to remove this behavior than it is
to add it in later.


Thread (15 messages)

« previous php.internals (#74111) next »