Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:52052 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 54595 invoked from network); 28 Apr 2011 09:43:42 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 28 Apr 2011 09:43:42 -0000 Authentication-Results: pb1.pair.com header.from=rasmus@lerdorf.com; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=rasmus@lerdorf.com; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain lerdorf.com from 74.125.83.170 cause and error) X-PHP-List-Original-Sender: rasmus@lerdorf.com X-Host-Fingerprint: 74.125.83.170 mail-pv0-f170.google.com Received: from [74.125.83.170] ([74.125.83.170:63431] helo=mail-pv0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 42/F4-28716-DC639BD4 for ; Thu, 28 Apr 2011 05:43:42 -0400 Received: by pvg16 with SMTP id 16so1857199pvg.29 for ; Thu, 28 Apr 2011 02:43:39 -0700 (PDT) Received: by 10.68.4.129 with SMTP id k1mr3373660pbk.72.1303983818942; Thu, 28 Apr 2011 02:43:38 -0700 (PDT) Received: from [192.168.200.140] (c-76-126-236-132.hsd1.ca.comcast.net [76.126.236.132]) by mx.google.com with ESMTPS id m10sm195669pbf.8.2011.04.28.02.43.37 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 28 Apr 2011 02:43:37 -0700 (PDT) Message-ID: <4DB936C8.2080801@lerdorf.com> Date: Thu, 28 Apr 2011 02:43:36 -0700 User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.14) Gecko/20110223 Thunderbird/3.1.8 MIME-Version: 1.0 To: Stas Malyshev , Reindl Harald , "internals@lists.php.net" References: <4DB923E6.3020307@sugarcrm.com> <4DB925D4.5090107@thelounge.net> <4DB926B4.5000307@sugarcrm.com> <20110428085859.GJ8496@phcomp.co.uk> In-Reply-To: <20110428085859.GJ8496@phcomp.co.uk> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] [RFC] Return type-hint From: rasmus@lerdorf.com (Rasmus Lerdorf) On 04/28/2011 01:58 AM, Alain Williams wrote: > On Thu, Apr 28, 2011 at 01:35:00AM -0700, Stas Malyshev wrote: >> Hi! >> >>> to find problems before your users? >> >> Sorry, this doesn't say much. It's a generic, of course we agree it's >> good to find bugs sooner rather than later. The question is why would >> that specific thing that is being proposed help - in which specific way? > > It would mean that the code that follows could benefit from the PHP run > time checking the return type -- at the point of return. Thus eliminating > following errors where the user does not check, eg: > > function array foo() { .... } > > $ret = foo(); > foreach($ret as $val) > .... I don't see this being useful at all. All you are doing is duplicating a runtime warning. We can't possibly know at compile-time whether this return value is an array or not, so there is no compile-time benefit. eg. function array foo() { $ret = bar(); return $ret; } So in this case we get a warning on the return and then another warning on the foreach(). We have not gained anything except an extra warning for the same problem in this code example. And this gets even worse if you start doing scalar return type checking. Now you are adding warnings for types that are safely interchangeable. -Rasmus