Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:74039 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 20727 invoked from network); 7 May 2014 22:30:04 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 7 May 2014 22:30:04 -0000 Authentication-Results: pb1.pair.com header.from=morrison.levi@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=morrison.levi@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.219.48 as permitted sender) X-PHP-List-Original-Sender: morrison.levi@gmail.com X-Host-Fingerprint: 209.85.219.48 mail-oa0-f48.google.com Received: from [209.85.219.48] ([209.85.219.48:51713] helo=mail-oa0-f48.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id B3/54-30354-BE3BA635 for ; Wed, 07 May 2014 18:30:03 -0400 Received: by mail-oa0-f48.google.com with SMTP id i4so2062406oah.7 for ; Wed, 07 May 2014 15:30:00 -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=ukQO9GYkEvHH6f7sweaTAjVBCRjsbxo5j3w+o56e7eA=; b=a2TedIMjKoWdeDShh04ZZ4B0U3EUbLT8UBKz7NnIJmYQJmXxRzGN1oH3vvKy45frrQ g2SB3z5o8eYATl3kJCmc0vCvQT77LdSSoBBbs1tSEmwTbYHVhdf1K+L/u+fWqUo1G6Jy aujEXKEvBN0xdddD/VopDH9Ie3KsHWTo87m8VZocX+1sL8qm8xxr1JjLcQmnSbC8eaWW JRTtu2EwQoB4skFNHOr3Xkt/k8Oq8bgIz6nF4fYRXZSX+szoYospMrOvfpu3hlTC+0AH SWvJHu/QpbKOuMt/6O0o4R9TCMOn1U/RAwUZaBGz/JgH1vP0uI9L2hwH0B2coqxAt7Mz 7piw== MIME-Version: 1.0 X-Received: by 10.60.145.139 with SMTP id su11mr19289697oeb.56.1399501800467; Wed, 07 May 2014 15:30:00 -0700 (PDT) Received: by 10.76.77.100 with HTTP; Wed, 7 May 2014 15:30:00 -0700 (PDT) In-Reply-To: References: <535E9AED.2080904@garfieldtech.com> <535ECB9E.5050701@garfieldtech.com> <535FC0DE.5050709@garfieldtech.com> Date: Wed, 7 May 2014 16:30:00 -0600 Message-ID: To: Lin Yo-An Cc: Larry Garfield , "internals@lists.php.net" Content-Type: multipart/alternative; boundary=047d7b5d30a0adf12a04f8d6e770 Subject: Re: [PHP-DEV] [RFC] Return Type Declarations From: morrison.levi@gmail.com (Levi Morrison) --047d7b5d30a0adf12a04f8d6e770 Content-Type: text/plain; charset=UTF-8 On Wed, May 7, 2014 at 11:02 AM, Lin Yo-An wrote: > Hi, > > Why using an additional ":" symbol for the return type? what about > considering this: > > function foo() string { } > > and for closure: > > $bar = 1; > $foo = function() use ($bar) string { > > }; > > I think removing ":" symbol is cleaner. Your point is valid, certainly. We could omit it. Here are two minor things to think about: 1. Syntax is a visual indicator. 2. Compatibility and familiarity to similar languages. Syntax can be used to visually indicate things to the programmer. For instance, the `()` in a conditional statement is not strictly necessary from a language design perceptive and Go chose to omit them. Valid Go: if $var === $null { } In our case the colon indicates that you are declaring a return type and you can read it aloud as "returns". While not strictly necessary it does give a visual indicator of what is going on. function date_diff(DateTime $a, DateTime $b) : DateInterval; The above function can be read aloud as: "Function date_diff takes DateTime a and DateTime b and returns DateInterval" The colon indicates 'returns'. You can infer this from the context, sure; again I did say this was a minor thing. In the case of the colon I value being compatible with Hack more than the small gain of omitting the colon. --047d7b5d30a0adf12a04f8d6e770--