2011/4/28 Martin Scotta <martinsco...@gmail.com>: * 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). 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 -- <hype> WWW: plphp.dk / plind.dk LinkedIn: plind BeWelcome/Couchsurfing: Fake51 Twitter: kafe15 </hype> -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php