Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:52073 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 41664 invoked from network); 28 Apr 2011 19:20:17 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 28 Apr 2011 19:20:17 -0000 Authentication-Results: pb1.pair.com smtp.mail=martinscotta@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=martinscotta@gmail.com; sender-id=pass; domainkeys=bad Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.220.170 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: martinscotta@gmail.com X-Host-Fingerprint: 209.85.220.170 mail-vx0-f170.google.com Received: from [209.85.220.170] ([209.85.220.170:37615] helo=mail-vx0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 6D/02-29189-1FDB9BD4 for ; Thu, 28 Apr 2011 15:20:17 -0400 Received: by vxb40 with SMTP id 40so2560693vxb.29 for ; Thu, 28 Apr 2011 12:20:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=dr2Aob0y99kSDnZOnfsMphWx3kNl9FRBf2Inp97lNws=; b=V91M+dvTWu5UlUJWJGGBgjx+Wwi5yWCkEbf3mAlb9ilUqMrQTYFgWpTXMlV9KfJmnE qhFfD9Ex9lC3yS1hxhW1IZppfUKk1vSHbRmSpjNtWBvfcM+UB81MrEtTOiSAzYfcUBVL TVuOPs7cCgNNCLLwYNp7VNpKOgqfdfghQHbsQ= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; b=GWfSaB4CXNCvG/ITuj+lcPbrH6D5Rw8ZezZeA7o6BKE7GHrG+BiWp+vtBmxLqDf1T/ Xu6J11E/Ju7QuscUDTMjNi3gqAJars+jZo8Cwfi2FkeGf7FyfT74rIs6w/17V2AADL0p v9DWkAwVvZkwi/pZxL3ZbqoL37N4AMBPhV8AQ= MIME-Version: 1.0 Received: by 10.52.73.33 with SMTP id i1mr550845vdv.133.1304018414672; Thu, 28 Apr 2011 12:20:14 -0700 (PDT) Received: by 10.220.189.197 with HTTP; Thu, 28 Apr 2011 12:20:14 -0700 (PDT) In-Reply-To: <1304016828.1561.103.camel@guybrush> References: <4DB923E6.3020307@sugarcrm.com> <4DB9A7BE.6010307@sugarcrm.com> <1304016828.1561.103.camel@guybrush> Date: Thu, 28 Apr 2011 16:20:14 -0300 Message-ID: To: =?ISO-8859-1?Q?Johannes_Schl=FCter?= Cc: Ferenc Kovacs , Stas Malyshev , Felipe Pena , internals Content-Type: multipart/alternative; boundary=20cf3071c7e8631a8804a1ff726c Subject: Re: [PHP-DEV] [RFC] Return type-hint From: martinscotta@gmail.com (Martin Scotta) --20cf3071c7e8631a8804a1ff726c Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Martin Scotta 2011/4/28 Johannes Schl=FCter > On Thu, 2011-04-28 at 20:04 +0200, Ferenc Kovacs wrote: > > > Why I need being "saved" from documenting my code properly? Anyway, t= he > > > function code defines the behavior, declaration of return type just > ensures > > > function would fail in runtime if your code tries to return unexpecte= d > data > > > - but how is it helpful? The client of this function doesn't even kno= w > that > > > before actually calling it! > > > > > > why did we added ppp if people can define in the documentation(or in th= e > > method name :/) that which method is public and which isn't > > with ppp i prevent the client code from doing something the > function/class author didn't expect. With this return hint the function > auther can force a runtime error when doing something wrong himself. > (which he has to check one way or the other using tests etc.) > > Return types are meant to ensure that you get what you asked for. This is really useful when you need to delegate to some component, specially if it'= s not of your own, although there are ways to avoid that patterns. IMHO I would not trust on any return value, as PHP did not ensure anything about them. Even more, I do not write code that depend on return values, I prefer to use input/output parameters, This is the safer way I've found to achieve the same behavior function no_return(ReturnStatus $returnStatus) { doSomething(); if ( itWasOk() ) { $returnStatus->setReturnValue( new Foo ); // return type hint $returnStatus->success(); // return status } elseif ( isWasCritical() ) { $returnStatus->setException( new RuntimeException ); $returnStatus->exception(); // return status } else { $returnStatus->fail(); // return status } } Of course I don't write all functions like this. This is pattern I use when I need to ensure that the type returned is valid= . johannes > > > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > --20cf3071c7e8631a8804a1ff726c--