Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:52087 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 13360 invoked from network); 29 Apr 2011 14:47:57 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 29 Apr 2011 14:47:57 -0000 Authentication-Results: pb1.pair.com header.from=martinscotta@gmail.com; sender-id=pass; domainkeys=bad Authentication-Results: pb1.pair.com smtp.mail=martinscotta@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.212.42 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.212.42 mail-vw0-f42.google.com Received: from [209.85.212.42] ([209.85.212.42:60545] helo=mail-vw0-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 88/FC-29189-C9FCABD4 for ; Fri, 29 Apr 2011 10:47:57 -0400 Received: by vwl1 with SMTP id 1so3133255vwl.29 for ; Fri, 29 Apr 2011 07:47:54 -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=7Tf6wNOGH9xoHZUU9EWsM2jnk1HFoJCDTh0r+T93xzw=; b=QAxaiwTbbD5MUXCgQN9Ok6BqFkUFj55UW8XzUHWnPr4rpfoosuAMHm+249OLa/bLRE SpaA1eN/BdcSIGSmqXqhUUHESW3AiANpm5e1ziN3FNv2BaKM0UBW3yYLmQtPlUC9hAYT udnlqejnajpJgv+4YhZtiuBjDmpFP4y1IrqmY= 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=XQuhgiMCrv6wIN2wGq6k2ht4Sy8IDS+A2DRN9T3qlznHBaURohz6dPJbz80GOZ0qZB kVEOBpGhLVznAP5i6ACn0pfKVhLcTf/5lNjS5/NzYekdsU4l8pO7raeDRWVUwedvDwsQ nXEizbCYSi1JyXZuq8qjsYsEdkCbXH2LKU/6Y= MIME-Version: 1.0 Received: by 10.52.115.165 with SMTP id jp5mr1767045vdb.13.1304088473859; Fri, 29 Apr 2011 07:47:53 -0700 (PDT) Received: by 10.220.189.197 with HTTP; Fri, 29 Apr 2011 07:47:53 -0700 (PDT) In-Reply-To: References: <4DB923E6.3020307@sugarcrm.com> <4DB9A7BE.6010307@sugarcrm.com> <1304016828.1561.103.camel@guybrush> Date: Fri, 29 Apr 2011 11:47:53 -0300 Message-ID: To: Peter Lind Cc: =?ISO-8859-1?Q?Johannes_Schl=FCter?= , Ferenc Kovacs , Stas Malyshev , Felipe Pena , internals Content-Type: multipart/alternative; boundary=bcaec54862f03d765704a20fc2da Subject: Re: [PHP-DEV] [RFC] Return type-hint From: martinscotta@gmail.com (Martin Scotta) --bcaec54862f03d765704a20fc2da Content-Type: text/plain; charset=ISO-8859-1 Martin Scotta On Thu, Apr 28, 2011 at 5:15 PM, Peter Lind wrote: > 2011/4/28 Martin Scotta : > > * snip * > > > 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, > > 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). > I understand why PHP does not have strict typing as much as I understand why PHP do not have good-qualities third-party libraries. I'm not saying that there aren't good libraries, but the language has many holes that makes almost impossible to build solid library (ie: include) All the strictness of ppp, typehint and the like are not restrict things, they are meant as boundaries for client code, to ensure the correct and well defined behavior. It's ok if you write all you code as procedural, or you don't like to write classes, but IMHO the language should provide a solid foundation for them, this way you can rely on libraries for common task and make your procedural code even simpler, shorter and safer. I'm not sure if return typehint will be a good idea, but I'm not against it. I believe the language has to deal with other "pending" stuff prior to this. PHP has many blind areas, whenever you call something, you don't know if you will return or it will just die in a non-sense Fatal error. > 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) { > > 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. > > 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 > > -- > > WWW: plphp.dk / plind.dk > LinkedIn: plind > BeWelcome/Couchsurfing: Fake51 > Twitter: kafe15 > > --bcaec54862f03d765704a20fc2da--