Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:52075 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 50272 invoked from network); 28 Apr 2011 20:16:03 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 28 Apr 2011 20:16:03 -0000 Authentication-Results: pb1.pair.com header.from=peter.e.lind@gmail.com; sender-id=pass; domainkeys=bad Authentication-Results: pb1.pair.com smtp.mail=peter.e.lind@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.216.42 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: peter.e.lind@gmail.com X-Host-Fingerprint: 209.85.216.42 mail-qw0-f42.google.com Received: from [209.85.216.42] ([209.85.216.42:58648] helo=mail-qw0-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id F3/63-29189-20BC9BD4 for ; Thu, 28 Apr 2011 16:16:03 -0400 Received: by qwi4 with SMTP id 4so1648240qwi.29 for ; Thu, 28 Apr 2011 13:15:59 -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:from:date :message-id:subject:to:cc:content-type:content-transfer-encoding; bh=xUE+F4IEBqCKRM6l4OTArRrwsra8w6oZN/5Fp0Gn4Vg=; b=dutybEchf7oXw/h0+DPcal9HEwxBxodZSF1fCkwGAl3TP6IylCP/wg831NfQIBaw8n mtp3QxXV2U33Av4uUVEPYAekxKVnCzie7jgD3/1wn8Ytru4hnraNeec2X/2ZjcWYe5iY YAUOmSZYJuG2g/7JX3pP+MAhXaPv8CNXtsISM= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type:content-transfer-encoding; b=TnrMmsodjzW/pxUMiMwYLiMxyOIveFC1eiZ3GIWeD4ihIrWMUa8jHx3t/D89pf788h V+CSmM6fsoiuX2713FwPIh+btB1VjCYrPlAZwEWc6+6bb5MM0adKTvOmkADCw9vmSRgQ ZGyDFPZ6/3+DlMqnN8WL7eXcBErdzoLObAcNc= Received: by 10.224.68.73 with SMTP id u9mr3306495qai.319.1304021759170; Thu, 28 Apr 2011 13:15:59 -0700 (PDT) MIME-Version: 1.0 Received: by 10.229.235.195 with HTTP; Thu, 28 Apr 2011 13:15:39 -0700 (PDT) In-Reply-To: References: <4DB923E6.3020307@sugarcrm.com> <4DB9A7BE.6010307@sugarcrm.com> <1304016828.1561.103.camel@guybrush> Date: Thu, 28 Apr 2011 22:15:39 +0200 Message-ID: To: Martin Scotta Cc: =?UTF-8?Q?Johannes_Schl=C3=BCter?= , Ferenc Kovacs , Stas Malyshev , Felipe Pena , internals Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] [RFC] Return type-hint From: peter.e.lind@gmail.com (Peter Lind) 2011/4/28 Martin Scotta : * snip * > IMHO I would not trust on any return value, as PHP did not ensure anythin= g > about them. > Even more, I do not write code that depend on return values, I prefer to > use input/output parameters, I cannot help but wonder why PHP is your language of choice. I mean no disrespect, but PHP does not have strict typing (for a reason) and forcing it upon PHP seems strange to me. Seeing as a) you'll either have to implement the return type hinting yourself in which case you'd know anyway what the return value is or b) you'd have to have others implement it in their libraries in which case you'd have to wait years for any noticeable effect, the feature seems useful only in edge cases (such as Hiphop, which I think one can question the mainstream usefulness of, currently). Personally, I read code if I'm not sure what a given function/method will return - or just test. I actually thought unit tests took care of issues like this. I don't think having a list of possible return values would make things simpler than the good old "try it and see" - which is one of the greatest assets of PHP. > This is the safer way I've found to achieve the same behavior > > function no_return(ReturnStatus $returnStatus) { > =C2=A0 doSomething(); > > =C2=A0 if ( itWasOk() ) > =C2=A0 { > =C2=A0 =C2=A0 =C2=A0 $returnStatus->setReturnValue( new Foo ); // return = type hint > =C2=A0 =C2=A0 =C2=A0 $returnStatus->success(); // return status > =C2=A0 } > =C2=A0 elseif ( isWasCritical() ) > =C2=A0 { > =C2=A0 =C2=A0 =C2=A0 $returnStatus->setException( new RuntimeException ); > =C2=A0 =C2=A0 =C2=A0 $returnStatus->exception(); // return status > =C2=A0 } > =C2=A0 else > =C2=A0 { > =C2=A0 =C2=A0 =C2=A0 $returnStatus->fail(); // return status > =C2=A0 } > } > > 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 val= id. I just return what I need to from the function/method or throw an exception. Indicating that you want to throw an exception instead of actually throwing one seems ... overly polite, at best. As far as I can tell, you'd have to check the ReturnStatus object anyway, so I don't see how you're any safer (PHP has functions for checking null values, false values, try/catch blocks and other things too). But maybe we're dealing with very different development environments and I just cannot see the usefulness of the suggested as it wouldn't make a positive difference in mine. Just a perspective from a typical webdev. Regards Peter --=20 WWW: plphp.dk / plind.dk LinkedIn: plind BeWelcome/Couchsurfing: Fake51 Twitter: kafe15