Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:73831 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 1109 invoked from network); 28 Apr 2014 18:16:20 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 28 Apr 2014 18:16:20 -0000 Authentication-Results: pb1.pair.com smtp.mail=larry@garfieldtech.com; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=larry@garfieldtech.com; sender-id=unknown Received-SPF: error (pb1.pair.com: domain garfieldtech.com from 66.111.4.25 cause and error) X-PHP-List-Original-Sender: larry@garfieldtech.com X-Host-Fingerprint: 66.111.4.25 out1-smtp.messagingengine.com Received: from [66.111.4.25] ([66.111.4.25:36391] helo=out1-smtp.messagingengine.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 91/76-49136-2FA9E535 for ; Mon, 28 Apr 2014 14:16:18 -0400 Received: from compute1.internal (compute1.nyi.mail.srv.osa [10.202.2.41]) by gateway1.nyi.mail.srv.osa (Postfix) with ESMTP id 556602148C for ; Mon, 28 Apr 2014 14:16:14 -0400 (EDT) Received: from frontend2 ([10.202.2.161]) by compute1.internal (MEProxy); Mon, 28 Apr 2014 14:16:14 -0400 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=message-id:date:from:mime-version:to :subject:references:in-reply-to:content-type :content-transfer-encoding; s=smtpout; bh=SRW5GQT6I81z8xrqlkmyNe ES/bE=; b=dOM3/bGCU2pYTfDkykRDGYEw0KHNH6oRJaRP1CLl8DHjS1n2pJIHyZ ehWmIz9UblQxIuQf0hcSq1IaAOt6KdYQMXLmESKArygXY81kX5IyD/GsEw+BdE29 FtBwD7RRnntZJK3i8BczbzheV64af9l/qT3XF2M/JGRgYSCIZ2R5I= X-Sasl-enc: 1YMdI2Q4kxysSPhb0Kf6Ku9MZOdv8NPutOt0JJ9ZZtpQ 1398708974 Received: from Palantirs-MacBook-Pro-2.local (unknown [63.250.249.138]) by mail.messagingengine.com (Postfix) with ESMTPA id 2215F68022E for ; Mon, 28 Apr 2014 14:16:14 -0400 (EDT) Message-ID: <535E9AED.2080904@garfieldtech.com> Date: Mon, 28 Apr 2014 13:16:13 -0500 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:24.0) Gecko/20100101 Thunderbird/24.4.0 MIME-Version: 1.0 To: internals@lists.php.net References: In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] [RFC] Return Type Declarations From: larry@garfieldtech.com (Larry Garfield) 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