Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:74111 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 65105 invoked from network); 9 May 2014 21:37:59 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 9 May 2014 21:37:59 -0000 Authentication-Results: pb1.pair.com smtp.mail=morrison.levi@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=morrison.levi@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.214.173 as permitted sender) X-PHP-List-Original-Sender: morrison.levi@gmail.com X-Host-Fingerprint: 209.85.214.173 mail-ob0-f173.google.com Received: from [209.85.214.173] ([209.85.214.173:50462] helo=mail-ob0-f173.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id E8/52-46741-6BA4D635 for ; Fri, 09 May 2014 17:37:59 -0400 Received: by mail-ob0-f173.google.com with SMTP id wm4so5559649obc.18 for ; Fri, 09 May 2014 14:37:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=L4U5Mxr4bLBiPFL/WrP1OSpCgWtUCsLUk/y3g4G++Lc=; b=tQ+R0xM4gtngPDerR42vD3MkRg0/ex2cA/bPVPu2ObTO67XRCmsVLxjHTWAdYlfn5W vOp6K7r5pIoNBlqSsFxcXm0y+cf+jPS1WS/1j1o728zXENrn+yeD84w4y8D4hN8eUaQ5 qqmpg7TJmgvdPJy07IL6hbLXlg7BXlzYbASozmxzmWIEB6ELLbGBuz9WMmYk0OTNyJdZ VGNIio9lcNbLYsiN3ryHYs8lHX0lujpcJphmWxAhuWejHLd94h8vDB55SjAyxHMquiX1 e2VYubRwkqlpIGmRcu0JxH/8wKBzFSzk9mgZCuRKJNp8BooAAdW5hFlWY0K+3ZW4Pj+g a0sg== MIME-Version: 1.0 X-Received: by 10.182.144.194 with SMTP id so2mr17418441obb.31.1399671475813; Fri, 09 May 2014 14:37:55 -0700 (PDT) Received: by 10.76.77.100 with HTTP; Fri, 9 May 2014 14:37:55 -0700 (PDT) In-Reply-To: References: <90B71511-4FB4-4916-9AC0-E3DD0D328C37@fb.com> <536D46C5.7040302@sugarcrm.com> Date: Fri, 9 May 2014 15:37:55 -0600 Message-ID: To: Josh Watzman Cc: Stas Malyshev , internals Content-Type: multipart/alternative; boundary=089e0158ab961e443304f8fe696e Subject: Re: [PHP-DEV] [RFC] Return Type Declarations pre-vote follow-up From: morrison.levi@gmail.com (Levi Morrison) --089e0158ab961e443304f8fe696e Content-Type: text/plain; charset=UTF-8 On Fri, May 9, 2014 at 3:32 PM, Josh Watzman 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. --089e0158ab961e443304f8fe696e--