Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:31309 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 36250 invoked by uid 1010); 29 Jul 2007 00:20:55 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 36235 invoked from network); 29 Jul 2007 00:20:55 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 29 Jul 2007 00:20:55 -0000 Authentication-Results: pb1.pair.com header.from=jeremy@peak8solutions.com; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=jeremy@peak8solutions.com; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain peak8solutions.com from 69.50.1.43 cause and error) X-PHP-List-Original-Sender: jeremy@peak8solutions.com X-Host-Fingerprint: 69.50.1.43 unknown Received: from [69.50.1.43] ([69.50.1.43:46927] helo=peak8solutions.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 94/01-27933-56DDBA64 for ; Sat, 28 Jul 2007 20:20:55 -0400 X-MimeOLE: Produced By Microsoft Exchange V6.5 Content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Date: Sat, 28 Jul 2007 18:20:47 -0600 Message-ID: In-Reply-To: <200707281905.27822.larry@garfieldtech.com> X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: [PHP-DEV] Re: Type-hinted return values in PHP5? Thread-Index: AcfRdEVJWZN/giK5SmegsiCpXiykvwAAdNwA References: <74.B1.05050.EADEC964@pb1.pair.com> <08.07.20814.2587AA64@pb1.pair.com> <46ABD596.3060005@zend.com> <200707281905.27822.larry@garfieldtech.com> To: "Larry Garfield" , Subject: RE: [PHP-DEV] Re: Type-hinted return values in PHP5? From: jeremy@peak8solutions.com ("Jeremy Privett") And Zend Studio does this for you already, if you use comment your code correctly. I really don't see a good use for this, either. Jeremy -----Original Message----- From: Larry Garfield [mailto:larry@garfieldtech.com]=20 Sent: Saturday, July 28, 2007 6:05 PM To: internals@lists.php.net Subject: Re: [PHP-DEV] Re: Type-hinted return values in PHP5? 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=20 context-assistance IDEs more data, so they could provide method-completion. =20 As nice a feature as that would be, I don't think it's worth modifying the=20 language syntax for. I agree that in a loosely typed language that sort of=20 thing needs to be checked by the application code anyway. --=20 Larry Garfield AIM: LOLG42 larry@garfieldtech.com ICQ: 6817012 "If nature has made any one thing less susceptible than all others of=20 exclusive property, it is the action of the thinking power called an idea,=20 which an individual may exclusively possess as long as he keeps it to=20 himself; but the moment it is divulged, it forces itself into the possession=20 of every one, and the receiver cannot dispossess himself of it." -- Thomas=20 Jefferson --=20 PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php