Re: [RFC] Supports 'finally' keyword for PHP exceptions
| From: | Xinchen Hui | Date: | Wed, 25 Jul 2012 07:22:05 +0000 |
| Subject: | Re: [RFC] Supports 'finally' keyword for PHP exceptions | ||
| References: | 1 2 3 4 5 6 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-61742@lists.php.net to get a copy of this message | ||
On Wed, Jul 25, 2012 at 3:23 AM, Galen Wright-Watson <ww.galen@gmail.com> wrote:
>
>
> On Tue, Jul 24, 2012 at 5:03 AM, Xinchen Hui <laruence@gmail.com> wrote:
>>
>> Sent from my iPhone
>>
>> 在 2012-7-24,19:51,Rafael Kassner <kassner@gmail.com> 写道:
>>>
>>>
>>> Thanks Laruence.
>>> If I perform something like this:
>>> function test() {
>>> try {
>>> return 2;
>>> } catch (Exception $e) {
>>> } finally {
>>> return 3;
>>> }
>>> }
>
>
> Reminds me of nerd sniping at Google
> (http://neil.fraser.name/news/2009/10/27/, bottom of the page).
>
> Worse example:
>
> $r = 1;
> try {
> return $r;
> } catch (Exception $e) {
> } finally {
> $r = 2;
> }
>
>>>
>>> What will be returned? There is no possibility to return something in
>>> finally, or finally will overwrite the return?
>>
>>
>> overweite,although I think it make no sense return in finally block
>>
>> But seems java allow that, so I implement it
>
>
> C# has perhaps more desirable behavior
> (http://blogs.msdn.com/b/jmstall/archive/2006/10/05/finally_5f00_vs_5f00_return.aspx):
> a return in a finally block is illegal, and the return value of a return
> statement in a try block is copied from the variable before the finally
> block is executed, so 1 will be returned. However, C# seems the odd one out
> (http://www.gettingclever.com/2008/07/return-from-finally.html).
Hi:
overwrite or not is easy to change, I impelent this according to
java's behavior.
but if we all think not overwrite is better, it's easy to change
thanks
--
惠新宸 laruence
Senior PHP Engineer
http://www.laruence.com