Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:73832 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 2499 invoked from network); 28 Apr 2014 18:19:12 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 28 Apr 2014 18:19:12 -0000 Authentication-Results: pb1.pair.com smtp.mail=admacedo@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=admacedo@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.213.169 as permitted sender) X-PHP-List-Original-Sender: admacedo@gmail.com X-Host-Fingerprint: 209.85.213.169 mail-ig0-f169.google.com Received: from [209.85.213.169] ([209.85.213.169:53605] helo=mail-ig0-f169.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 75/C6-49136-F9B9E535 for ; Mon, 28 Apr 2014 14:19:11 -0400 Received: by mail-ig0-f169.google.com with SMTP id h18so5028222igc.2 for ; Mon, 28 Apr 2014 11:19:08 -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:cc :content-type; bh=OT9tv2+phMnse85b7Q8r/2NIHbdalo/dLO7J81anZ2Y=; b=bQY/YA2v7h9NqpVR84J8Aojv2TnQawfsW9HYm2KbDgUtmu2IsgYGvu1kQ2nbhlcQ+q qwmvLcXutRqtc8CU+GITEUFtGOLA520gp2XzaouSQcqgy9rDdc2hTtl5zUpEniJV3TeE wO34ItE+tEJNpo53Rx1zuo5wRNXx04eZnT2N48dyefHh4SHkbfWuZLsRPEHg6Qq/SXDz NYOlojRtI01UaiA69om7dq9f07Aqj+gCkSsPuZK03gDSd/7ZEEJVxkQkYjz+xPC4Oed2 RDICISIPkepohe3Zc5G/P1JL12l29VIOHyDUWdqX6FQGseI3atYq4CNGPyjcig4vN+KI 7kRg== X-Received: by 10.50.85.18 with SMTP id d18mr25622872igz.42.1398709148634; Mon, 28 Apr 2014 11:19:08 -0700 (PDT) MIME-Version: 1.0 Received: by 10.64.17.162 with HTTP; Mon, 28 Apr 2014 11:18:28 -0700 (PDT) In-Reply-To: <535E9AED.2080904@garfieldtech.com> References: <535E9AED.2080904@garfieldtech.com> Date: Mon, 28 Apr 2014 19:18:28 +0100 Message-ID: Cc: PHP Internals Content-Type: text/plain; charset=UTF-8 Subject: Re: [PHP-DEV] [RFC] Return Type Declarations From: admacedo@gmail.com (Daniel Macedo) (Apparently only replied to Sebastian while on mobile :) I know this RFC does not address multiple return types on purpose. But supposing it's implemented in its current form, what would be a possible syntax for multiple/mixed return types? Namely for the usual suspects of string|null, array|null, Class|bool, or ClassA|ClassB|bool, etc... Something along those lines. Cheers On Mon, Apr 28, 2014 at 7:16 PM, Larry Garfield wrote: > On 4/24/14, 10:59 AM, Levi Morrison wrote: >> >> My dear Internals friends, >> >> I have spent the last month drafting an RFC that allows return types: >> https://wiki.php.net/rfc/returntypehinting >> >> Notable items: >> - Differences from past RFCs are summarized in the RFC: >> https://wiki.php.net/rfc/returntypehinting#differences_from_past_rfcs >> - The patch includes basic opcache and reflection support. It also has >> phpt tests. >> - Informal performance tests indicate that the patch did not fubar >> performance; if desired a more detailed test can be conducted before >> voting. >> - This RFC does not add, modify, or remove keywords at all; this >> notably >> excludes type-hints for scalars. Supporting scalar type declarations is >> outside the scope of this RFC; if you are interested in supporting scalar >> type declarations please discuss it elsewhere. >> >> As a friendly reminder, everyone on this list is interested in developing >> a >> better PHP and the definitions of 'better' vary from person to person. >> Please be civil and constructive while discussing this RFC. Thank you! >> >> Some thanks, regardless if the RFC is accepted: >> - For providing a patch: Joe Watkins. >> - For helping me iterate on RFC drafts: Bob Wienand, Nikita Popov and >> Anthony Ferrara >> - For previous RFCs on this topic: Felipe Pena and Will Fitch. I >> gleaned >> valuable knowledge from your proposals and the discussion around them. > > > Simple, targeted, focused, I like. I very much like the NULL handling, as > it means as a caller I have to do less work. > > One bit strikes me as odd. In the invalid examples, you have this example: > > function foo(): array { > yield []; > } > > which generates this error: > > Fatal error: Generators may only yield objects, array is not a valid type in > %s on line %d > > Except Generators can totally yield arrays currently: > > function foo() { > yield []; > } > foreach (foo() as $x) print_r($x) . PHP_EOL; > > The above works perfectly on 5.5.10, where I just tested it. > > So what's with that error condition? Clearly from the RFC we can specify > array as a return type, so I don't know why it calls out generators as > specially limited. > > As I write that I suspect it's because generators actually "return" an > interator object, and so the return type of the generator is being > interpreted relative to the construction, not iteration, of the generator. > That seems like a likely source of confusion, as I would, as a developer, > expect to be specifying the type that gets returned from iteration, not from > construction, so that my foreach loop (or similar) can rely on the type > being returned. > > I think this part warrants further consideration. The rest of the RFC I > fully look forward to using. > > As far as the order of keywords in a closure, what order does Hack use? The > rest of the syntax seems based on it, so it seems sensible to follow suit. > (I couldn't find that information from 60 seconds on hacklang.org, but it > may be there.) > > --Larry Garfield > > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php >