Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:67868 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 23709 invoked from network); 26 Jun 2013 13:36:33 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 26 Jun 2013 13:36:33 -0000 Authentication-Results: pb1.pair.com smtp.mail=julienpauli@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=julienpauli@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.212.49 as permitted sender) X-PHP-List-Original-Sender: julienpauli@gmail.com X-Host-Fingerprint: 209.85.212.49 mail-vb0-f49.google.com Received: from [209.85.212.49] ([209.85.212.49:56293] helo=mail-vb0-f49.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id E8/B7-18025-F5EEAC15 for ; Wed, 26 Jun 2013 09:36:31 -0400 Received: by mail-vb0-f49.google.com with SMTP id 12so10703381vbf.36 for ; Wed, 26 Jun 2013 06:36:28 -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:from:date :x-google-sender-auth:message-id:subject:to:cc:content-type; bh=iTZx190RyCWwKEwykAv7ttdrXfLP1OLrvZYGNcHAp7o=; b=QjPDVBO+vsPHhDv3i1IwxNN9DBjqG1LNejksOocn0yd4liRLG0Pni6IErb5DysgiWg ae4o2im9dpjPvrJSWi/qfH6RKGSfCKfcKEgLlpWi1dE705rSG3tj0LAnFDOoGeZFvieP COVXl69sIRf/XxxLa8gYbCOA0K7yvW20DQI9aXHF4mg8SF0gmc4Lj9j+4OUE2LXxL84P ZHP959+qsZdTgn5GvL8dzbmmj+JsARXYuwpmXIbEftIdJL7b7zvTw3zzUVIAohOK1u+D YgKmnczokWOwXAiUPp72v5OT3OBwRAIgoPazMnBkwMCZFFW04swFknxRgJsCslKjeDSJ xcRQ== X-Received: by 10.52.36.113 with SMTP id p17mr1452265vdj.51.1372253787931; Wed, 26 Jun 2013 06:36:27 -0700 (PDT) MIME-Version: 1.0 Sender: julienpauli@gmail.com Received: by 10.220.188.73 with HTTP; Wed, 26 Jun 2013 06:35:47 -0700 (PDT) In-Reply-To: References: Date: Wed, 26 Jun 2013 15:35:47 +0200 X-Google-Sender-Auth: 53Dkq2wnAi_3HlE8vFOTsxXfUK0 Message-ID: To: Patrick ALLAERT Cc: Maxwell , Sherif Ramadan , Florin Patan , "internals@lists.php.net" Content-Type: multipart/alternative; boundary=20cf307c9b60924b3604e00ebbda Subject: Re: [PHP-DEV] Request for comments - new PHP feature: return typing From: jpauli@php.net (Julien Pauli) --20cf307c9b60924b3604e00ebbda Content-Type: text/plain; charset=ISO-8859-1 On Wed, Jun 26, 2013 at 2:58 PM, Patrick ALLAERT wrote: > 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); > } > } > +1 for the global idea as this would help so much OO programs and framework based programs. But what Sherif said proves as well the limits of the idea. PHP is not strongly typed. So each check, should it be type hinting or return type hinting, has to be done at runtime , which is bad for performances. Not talking about the type juggling which could lead the programmer as shooting himself. Julien.Pauli --20cf307c9b60924b3604e00ebbda--