Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:74114 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 30913 invoked from network); 10 May 2014 09:07:16 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 10 May 2014 09:07:16 -0000 Authentication-Results: pb1.pair.com header.from=linepogl@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=linepogl@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.219.49 as permitted sender) X-PHP-List-Original-Sender: linepogl@gmail.com X-Host-Fingerprint: 209.85.219.49 mail-oa0-f49.google.com Received: from [209.85.219.49] ([209.85.219.49:46500] helo=mail-oa0-f49.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 73/BD-46741-34CED635 for ; Sat, 10 May 2014 05:07:16 -0400 Received: by mail-oa0-f49.google.com with SMTP id eb12so6036529oac.36 for ; Sat, 10 May 2014 02:07:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=CHkp+rsmgoBc2zajOMbujmvN3PmzWe805IsS1imDh/I=; b=EQZ5IrPZWU83bp5k9eu86jk+3HfzEOIeodWckwa0VVzZF4E6UqvR3RiM0m2pJtDwql +/9UQhS6wd8uuPqFdla5Uy/+0RRlKAZ4Td5v7CCGlIXUn/oa/J98paClngJvnUPnuSmX YY9AiDefsh4IrnUKsAP5zcKfS2GLKcbw3SFd0JLnJPMCmORG+ljxbhqxN+DZ5RAeliXq 1XjTE78Jrvo4j4CmATtEY9S7p7oTId8OIjPM8fpbYrW/tsz9/rm0jm7bHSectzC3JKgu 0B+p6gf24h/8SyIEdeB3Aw66A4nxvqhtTe+9zCTmj1vyHSqD23q9S9M00OHQu1UvbgZh dj8A== X-Received: by 10.182.28.104 with SMTP id a8mr20033482obh.30.1399712832671; Sat, 10 May 2014 02:07:12 -0700 (PDT) MIME-Version: 1.0 Received: by 10.76.132.6 with HTTP; Sat, 10 May 2014 02:06:52 -0700 (PDT) In-Reply-To: References: <90B71511-4FB4-4916-9AC0-E3DD0D328C37@fb.com> <536D46C5.7040302@sugarcrm.com> Date: Sat, 10 May 2014 11:06:52 +0200 Message-ID: To: Josh Watzman Cc: Stas Malyshev , Levi Morrison , internals Content-Type: multipart/alternative; boundary=089e015372c62dd61f04f9080a06 Subject: Re: [PHP-DEV] [RFC] Return Type Declarations pre-vote follow-up From: linepogl@gmail.com (Lazare Inepologlou) --089e015372c62dd61f04f9080a06 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Hello, 2014-05-09 23:32 GMT+02:00 Josh Watzman : > > 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. > > I understand, and this is the same argument LeviM has been making. (We > just discussed on IRC in #hhvm extensively.) > > 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 featu= re > when we were adding the Hack type system onto PHP. > > > The type 'self' is not late bound, unlike 'static' and exists in the > language elsewhere; I am not introducing a new keyword 'self' in this RFC= . > > We discussed this on IRC and came to consensus that "self" is just fine, > though not necessarily terribly useful if you think further than just > enforcing the return type, to how that information might be propagated an= d > used at the callsite -- for example by the Hack static typechecker, or ev= en > by a human. The type "static" tends to be what you want. But this isn't a > huge deal -- "self" as proposed isn't *wrong*. > > As far as I understand, the keyword "self" was just inherited from argument type hinting. The keyword "static" is not used there, so it was not carried over. Maybe "static" should be introduced to both cases, but in a separate RFC. Lazare INEPOLOGLOU Ing=C3=A9nieur Logiciel --089e015372c62dd61f04f9080a06--