Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:67864 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 16622 invoked from network); 26 Jun 2013 12:58:54 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 26 Jun 2013 12:58:54 -0000 Authentication-Results: pb1.pair.com smtp.mail=patrick.allaert@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=patrick.allaert@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.219.43 as permitted sender) X-PHP-List-Original-Sender: patrick.allaert@gmail.com X-Host-Fingerprint: 209.85.219.43 mail-oa0-f43.google.com Received: from [209.85.219.43] ([209.85.219.43:64032] helo=mail-oa0-f43.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 74/56-18025-D85EAC15 for ; Wed, 26 Jun 2013 08:58:53 -0400 Received: by mail-oa0-f43.google.com with SMTP id i7so14878687oag.30 for ; Wed, 26 Jun 2013 05:58:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type; bh=icsJE6kzJhgPuTaCA/o9cvjqnYaPM0hpdzx4pCCYXJc=; b=gyMFnSSmm3OwDpZUPaYtJkEHvgysaZkVAV0Y/nLMup2CVD1nPtMmgswnbGhCNiQ8U2 k2a0cidasMr8B5XkfIC2Qiy6PxmU+aoZvGUT2ET2WqQyKqL0jQlOtYTvn1k3vUKjDbgm P7s/1kOKQ6xi3E3T5ThVy2Kna3GpzIx8VIr+kjF9wseDU6FVsRY7lCpiFk9/4kt9K6cI /UN6ljXgZri4muV5Uy/zlpejCbYPKAbaJLmVT9Dt2HIi6Zw5bePVD4VDwhGw0T37jG/m DXlrCal5HguG3wBFi8nCJKNg+X+DM0EOKuAzMf1+uAQfAyYuKEUbD2kLClMilOME375L c2jw== MIME-Version: 1.0 X-Received: by 10.60.178.136 with SMTP id cy8mr404077oec.58.1372251530836; Wed, 26 Jun 2013 05:58:50 -0700 (PDT) Sender: patrick.allaert@gmail.com Received: by 10.76.7.169 with HTTP; Wed, 26 Jun 2013 05:58:50 -0700 (PDT) In-Reply-To: References: Date: Wed, 26 Jun 2013 14:58:50 +0200 X-Google-Sender-Auth: FTOuhW3rJhYiIaBB5TxRJCT-iec Message-ID: To: Maxwell Cc: Sherif Ramadan , Florin Patan , "internals@lists.php.net" Content-Type: text/plain; charset=UTF-8 Subject: Re: [PHP-DEV] Request for comments - new PHP feature: return typing From: patrickallaert@php.net (Patrick ALLAERT) 2013/6/26 Maxwell : > Sherif, > I have to disagree with you on this in the same way that we have type hints > for input variables on methods, this could also be useful. > Consider an interface with a getter method defined. As it stands now in > php, they're not entirely useful, since you can't define what type of > object your expecting from the implementer. That greatly reduces the > functionality of an interface and this proposal gives solution to that > problem. > > Florin, > I think the overall concept is good, I want to see something like this in > the future, but I think this might be the wrong approach. I don't think we > should be hinting primitives. if we're going to have a return type hint on > a method, I would have it match the functionality of the input type hints > for functions we already have, where you can hint at an instance of an > object type, such as Iterator or StdClass, or an array, but not hint > primitives such as int and string, like I currently see in the draft. > Also, you should be aware that your proposed syntax for the return type ( > ) is interfering with: > https://wiki.php.net/rfc/protocol_type_hintingand seems unnecessary to > me. Thanks Maxwell, you summarized very well what I was thinking about it. So +1 from me for the general feature at a first glance, but it should then be very close to what is possible with input type hinting. It makes it possible to write interfaces that acts like specifications and to easier the writing of: class Foo { public function bar($input) { $return = Baz::foo($input); if (!$return instanceof ReturnType) trigger_error("Cannot divide by zero", E_USER_ERROR); // or throwing some RuntimeException return $return; } } to: class Foo { public function bar($input) { return Baz::foo($input); } }