Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:78647 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 60930 invoked from network); 4 Nov 2014 16:29:05 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 4 Nov 2014 16:29:05 -0000 Authentication-Results: pb1.pair.com header.from=ajf@ajf.me; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=ajf@ajf.me; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain ajf.me designates 192.64.116.216 as permitted sender) X-PHP-List-Original-Sender: ajf@ajf.me X-Host-Fingerprint: 192.64.116.216 imap10-3.ox.privateemail.com Received: from [192.64.116.216] ([192.64.116.216:51413] helo=imap10-3.ox.privateemail.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 78/49-06676-FCEF8545 for ; Tue, 04 Nov 2014 11:29:03 -0500 Received: from localhost (localhost [127.0.0.1]) by mail.privateemail.com (Postfix) with ESMTP id 01D862400DC; Tue, 4 Nov 2014 11:29:00 -0500 (EST) X-Virus-Scanned: Debian amavisd-new at imap10.ox.privateemail.com Received: from mail.privateemail.com ([127.0.0.1]) by localhost (imap10.ox.privateemail.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id GELuFEK-ZIdH; Tue, 4 Nov 2014 11:28:59 -0500 (EST) Received: from oa-res-26-28.wireless.abdn.ac.uk (oa-res-26-28.wireless.abdn.ac.uk [137.50.26.28]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.privateemail.com (Postfix) with ESMTPSA id 6005F24005D; Tue, 4 Nov 2014 11:28:58 -0500 (EST) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 8.0 \(1990.1\)) In-Reply-To: Date: Tue, 4 Nov 2014 16:28:56 +0000 Cc: Stas Malyshev , Robert Stoll , PHP Internals Content-Transfer-Encoding: quoted-printable Message-ID: <28A749C7-A600-4C7A-86A9-7166F2955EE0@ajf.me> References: <002601cff777$eb923430$c2b69c90$@tutteli.ch> <000601cff80a$972e0250$c58a06f0$@tutteli.ch> <5458937F.9020304@sugarcrm.com> <0776A65F-D49A-4E8C-9771-6B5E5C4EA77E@ajf.me> To: Chris Wright X-Mailer: Apple Mail (2.1990.1) Subject: Re: [PHP-DEV] Types on the right or on the left From: ajf@ajf.me (Andrea Faulds) > On 4 Nov 2014, at 11:50, Chris Wright wrote: >=20 > On 4 November 2014 10:32, Andrea Faulds wrote: >=20 > > I thought it was inconsistent, but after discussions on = StackOverflow, I don't think it actually is. > Return types describe the = return type of a function, not the type of a function. So there's no = reason > they have to go before the function name like parameter types = do. >=20 > So, in a sentence: >=20 > In PHP, input types go on the left and output types go on the right. >=20 > This sounds like a convention that could be established and followed, = and no-one could reasonably call it inconsistent if it was adhered to. >=20 That=E2=80=99s not quite what I meant, but I=E2=80=99d also agree with = that convention. For parameters, the type is of the thing itself: function foo(Foo $foo, Bar $bar); Here, $foo is of the type Foo, and $bar is of the type Bar. But say if we were to add return types like this: function FooBar qux(); The type of qux isn=E2=80=99t a FooBar, it=E2=80=99s a function (more = accurately, an argument-less, return-anything function). FooBar isn=E2=80=99= t what qux is, it=E2=80=99s not qux=E2=80=99s type, merely what it = returns. In a sense, I=E2=80=99d say there=E2=80=99s already a type = here: `function`. Compare it to this: function qux(): FooBar; FooBar is what qux returns, `function` is what qux is. If we were to hypothetically add typed properties with the same syntax = Hack has, they=E2=80=99d look like this: public Foo $foo; This would be consistent with parameters. And I think it goes along well = with return types at the end: public Foo $foo; public function foobar(): FooBar; Here, it=E2=80=99s clear the second item is a function, and the previous = item is a property of type Foo. =E2=80=A6but hey, I could be wrong. Does this make sense to anyone? -- Andrea Faulds http://ajf.me/