Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:31308 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 28709 invoked by uid 1010); 29 Jul 2007 00:05:44 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 28694 invoked from network); 29 Jul 2007 00:05:44 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 29 Jul 2007 00:05:44 -0000 Authentication-Results: pb1.pair.com header.from=larry@garfieldtech.com; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=larry@garfieldtech.com; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain garfieldtech.com from 216.148.227.153 cause and error) X-PHP-List-Original-Sender: larry@garfieldtech.com X-Host-Fingerprint: 216.148.227.153 rwcrmhc13.comcast.net NetCache Data OnTap 5.x Received: from [216.148.227.153] ([216.148.227.153:43876] helo=rwcrmhc13.comcast.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id F5/00-27933-6D9DBA64 for ; Sat, 28 Jul 2007 20:05:44 -0400 Received: from earth.ufp (c-71-228-13-89.hsd1.il.comcast.net[71.228.13.89]) by comcast.net (rwcrmhc13) with ESMTP id <20070729000540m13006plu7e>; Sun, 29 Jul 2007 00:05:40 +0000 Received: from localhost (localhost [127.0.0.1]) by earth.ufp (Postfix) with ESMTP id DE675D8169 for ; Sat, 28 Jul 2007 19:05:39 -0500 (CDT) Received: from earth.ufp ([127.0.0.1]) by localhost (earth.ufp [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id UFSDKEuIW7IH for ; Sat, 28 Jul 2007 19:05:39 -0500 (CDT) Received: from vulcan.ufp (vulcan.ufp [192.168.42.4]) by earth.ufp (Postfix) with ESMTP id B3E65D8166 for ; Sat, 28 Jul 2007 19:05:29 -0500 (CDT) To: internals@lists.php.net Date: Sat, 28 Jul 2007 19:05:27 -0500 User-Agent: KMail/1.9.6 References: <74.B1.05050.EADEC964@pb1.pair.com> <08.07.20814.2587AA64@pb1.pair.com> <46ABD596.3060005@zend.com> In-Reply-To: <46ABD596.3060005@zend.com> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-ID: <200707281905.27822.larry@garfieldtech.com> Subject: Re: [PHP-DEV] Re: Type-hinted return values in PHP5? From: larry@garfieldtech.com (Larry Garfield) On Saturday 28 July 2007, Stanislav Malyshev wrote: > > It would give you similar benefits to input type hinting, but instead of > > "Functions are now able to force parameters to be objects...", it would > > also read "Calling functions are now able to expect return types to be > > objects...". If a function was defined to return object Z, but instead > > returned false, then obviously there is something wrong and it could be > > caught before calling code sees it expecting it to be something else. > > Catching language-level error in application code is usually harder than > just handling it in user code. And if you are talking about distinction > between false/null and actual object, language level is the wrong level > to catch such things. > If you handle the error in runtime, you could have the check as well. If > you don't, the script breaks anyway, so it is not going to help you much. > Even more, the return value is the product of the module code, while > input values are product of the outside code. So when you say "I'm going > to process only type X, and I make a requirement for others to pass only > X to me", it makes for me more sense than saying "I'm going to return > only type X so I'm making restriction for myself to return only type X". > The latter is more like declaring variable types, which have its > functions in compiled languages but usually is not happening in dynamic > interpreted languages. > Also, since from the client side there's no way to check if the function > you are calling actually does have the return type restriction, it's > quite hard to program basing on that from the client side. So you > actually check it in one place (library) and use it in entirely > different place (client) which is usually bad idea since the client > becomes too reliant on internal details of the library. > > > If I, or someone else decided to make a patch for this, and assuming it > > worked exactly like I described, would it be accepted? > > I don't know... I personally don't see much use for it, but others may > disagree. I think the only serious advantage I could see would be to allow context-assistance IDEs more data, so they could provide method-completion. As nice a feature as that would be, I don't think it's worth modifying the language syntax for. I agree that in a loosely typed language that sort of thing needs to be checked by the application code anyway. -- Larry Garfield AIM: LOLG42 larry@garfieldtech.com ICQ: 6817012 "If nature has made any one thing less susceptible than all others of exclusive property, it is the action of the thinking power called an idea, which an individual may exclusively possess as long as he keeps it to himself; but the moment it is divulged, it forces itself into the possession of every one, and the receiver cannot dispossess himself of it." -- Thomas Jefferson