Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:52050 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 49409 invoked from network); 28 Apr 2011 08:59:21 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 28 Apr 2011 08:59:21 -0000 Authentication-Results: pb1.pair.com header.from=addw@phcomp.co.uk; sender-id=permerror Authentication-Results: pb1.pair.com smtp.mail=addw@phcomp.co.uk; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain phcomp.co.uk designates 80.68.91.63 as permitted sender) X-PHP-List-Original-Sender: addw@phcomp.co.uk X-Host-Fingerprint: 80.68.91.63 bytemark.phcomp.co.uk Received: from [80.68.91.63] ([80.68.91.63:40608] helo=bytemark.phcomp.co.uk) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 6D/14-28716-66C29BD4 for ; Thu, 28 Apr 2011 04:59:19 -0400 Received: from freshmint.phcomp.co.uk ([78.32.209.33] helo=mint.phcomp.co.uk) by bytemark.phcomp.co.uk with esmtps (TLSv1:AES256-SHA:256) (Exim 4.71) (envelope-from ) id 1QFN3s-0005zX-59; Thu, 28 Apr 2011 09:59:00 +0100 Received: from addw by mint.phcomp.co.uk with local (Exim 4.63) (envelope-from ) id 1QFN3r-0003ur-ME; Thu, 28 Apr 2011 09:58:59 +0100 Date: Thu, 28 Apr 2011 09:58:59 +0100 To: Stas Malyshev Cc: Reindl Harald , "internals@lists.php.net" Message-ID: <20110428085859.GJ8496@phcomp.co.uk> Mail-Followup-To: Stas Malyshev , Reindl Harald , "internals@lists.php.net" References: <4DB923E6.3020307@sugarcrm.com> <4DB925D4.5090107@thelounge.net> <4DB926B4.5000307@sugarcrm.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <4DB926B4.5000307@sugarcrm.com> User-Agent: Mutt/1.4.2.2i Organization: Parliament Hill Computers Ltd Subject: Re: [PHP-DEV] [RFC] Return type-hint From: addw@phcomp.co.uk (Alain Williams) 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 must admit that this is much less useful than checking of argument types going into functions, where the writer of the function (part of a libarary perhaps) does not trust the function user to get validation/... right. But this is another discussion. The other way in that this could be very helpful is with run time optimisation, especially for things like HipHop - think of the optimisation that it could make if it knew the real return type, eg: function int bar() { ... } (The argument about argument types is even more so here.) > >the second one will produce an error if empty string is given > >while an empty array would be accepted > > And it is better because?.. > Also please note we are discussing strict return typing. I am also mindful that the proposed syntax does not allow description of functions that return more than one type; where they return something to indicate a failure (or end) - typically FALSE or NULL. So maybe something like the following could cope with them: function (array | bool) baz() { ... } or even: function (array | false) baz() { ... } I can see that some may prefer commas: function (array, false) baz() { ... } although, to me, that looks like a list - I prefer vertical bar. HipHop would be able to optimise things like: if( ($ret = baz()) !== FALSE ) { ... } [**] https://github.com/facebook/hiphop-php/wiki/ -- Alain Williams Linux/GNU Consultant - Mail systems, Web sites, Networking, Programmer, IT Lecturer. +44 (0) 787 668 0256 http://www.phcomp.co.uk/ Parliament Hill Computers Ltd. Registration Information: http://www.phcomp.co.uk/contact.php #include