Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:58254 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 10484 invoked from network); 28 Feb 2012 16:32:36 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 28 Feb 2012 16:32:36 -0000 Authentication-Results: pb1.pair.com smtp.mail=kiall@managedit.ie; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=kiall@managedit.ie; sender-id=pass Received-SPF: pass (pb1.pair.com: domain managedit.ie designates 209.85.214.42 as permitted sender) X-PHP-List-Original-Sender: kiall@managedit.ie X-Host-Fingerprint: 209.85.214.42 mail-bk0-f42.google.com Received: from [209.85.214.42] ([209.85.214.42:52357] helo=mail-bk0-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id C9/52-34356-2A10D4F4 for ; Tue, 28 Feb 2012 11:32:35 -0500 Received: by bkcje9 with SMTP id je9so406895bkc.29 for ; Tue, 28 Feb 2012 08:32:31 -0800 (PST) Received-SPF: pass (google.com: domain of kiall@managedit.ie designates 10.204.136.207 as permitted sender) client-ip=10.204.136.207; Authentication-Results: mr.google.com; spf=pass (google.com: domain of kiall@managedit.ie designates 10.204.136.207 as permitted sender) smtp.mail=kiall@managedit.ie; dkim=pass header.i=kiall@managedit.ie Received: from mr.google.com ([10.204.136.207]) by 10.204.136.207 with SMTP id s15mr1691986bkt.43.1330446751694 (num_hops = 1); Tue, 28 Feb 2012 08:32:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=managedit.ie; s=google; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=CuhEpA2N5hYP1CfKEM1P/Cwfj+A7cb+eEc9SNw+Z7bM=; b=Bl/HkINyxfAr/uBYLk+rI5PNWDgVC1M37kZlzczSO4T8BSsOQydJCF7xWdurYqAXqx 0clTL17Lp+QbAMyoH11kTcijPYB4+qNq+8KGwwfgeVxE5AMUKx6E+yn6Q0hGqYBy3d5u ct5oYZVwBU7YuBkyvCg6Ja/niwxTDdjb1fNnU= Received: by 10.204.136.207 with SMTP id s15mr1391387bkt.43.1330446751411; Tue, 28 Feb 2012 08:32:31 -0800 (PST) MIME-Version: 1.0 Received: by 10.204.42.74 with HTTP; Tue, 28 Feb 2012 08:32:11 -0800 (PST) In-Reply-To: References: <01a901ccf622$0645f230$12d1d690$@alliantinternet.com> Date: Tue, 28 Feb 2012 16:32:11 +0000 Message-ID: To: Arvids Godjuks Cc: Richard Lynch , internals@lists.php.net Content-Type: multipart/alternative; boundary=0015175cfa3402af2604ba08c6f9 X-Gm-Message-State: ALoCoQkW1RpBYudiPcYgwtRoLdAys89LHTCHONO3AdrvcoKt1qb9GRSjPC+epSz3cKUHu+TEx7YZ Subject: Re: [PHP-DEV] Possibility to add finally to try/catch? From: kiall@managedit.ie (Kiall Mac Innes) --0015175cfa3402af2604ba08c6f9 Content-Type: text/plain; charset=ISO-8859-1 Completely agree - finally comes into its own in more complex code, the kind of code that is quite hard to distill into a few line "compelling example". Yes, You could abstract the try/catch into a new (and un-needed) function to try and emulate the behavior of finally.. Unless, for example, you re-throw the exception after logging in the catch. But - This really is no substitute for a native language construct try { $fh = fopen($filename); // Do some work on the file + encounter an error. throw new Exception(); } catch (Exception $e) { $log->add(Log::ERROR, "Something went wrong", $e); throw $e; } finally { fclose($fh); } Thanks, Kiall On Tue, Feb 28, 2012 at 4:12 PM, Arvids Godjuks wrote: > It's quite hard to think of a compelling example. Usually you just > write the code and realize that "Yea, a 'finally' statement would make > a lot of sense here". > I believe it's the kind of functionality that you learn to use in > time, just like __set, __get, __sleep, __wakeup. If first two are no > brainier these days, the last two to me where "wtf? does anyone use > that? Where I need them at all?!". It was like that for 3-4 years. > Until I got the code witch actually made an active use of these two > and I understood the purpose. > Same goes to finally. I remember using in JavaScript a few times, helped a > lot. > And it just makes sense to add to complete the try {} catch {} finally > {} template. > My 2 cents. > > 2012/2/28 Richard Lynch : > > On Tue, February 28, 2012 8:22 am, Kiall Mac Innes wrote: > >> +1000 > >> > >> This is a feature that I've always wanted in PHP, My main reason being > >> to > >> reduce code duplication. eg > >> > >> try { > >> $fh = fopen($filename); > >> > >> // Do some work on the file + encounter an error. > >> throw new Exception(); > >> } catch (Exception $e) { > >> // Log an error or something > > + if ($fh) fclose($fh); //many PHP file errors NULL out the $fh > > + } > > - > } finally { > > - > fclose($fh); > > - > } > > > > Another non-compelling example... > > > > Still not saying "finally" is a bad idea. > > > > Just want a compelling use case before I would vote... > > > > -- > > brain cancer update: > > http://richardlynch.blogspot.com/search/label/brain%20tumor > > Donate: > > > https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=FS9NLTNEEKWBE > > > > > > > > -- > > PHP Internals - PHP Runtime Development Mailing List > > To unsubscribe, visit: http://www.php.net/unsub.php > > > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > --0015175cfa3402af2604ba08c6f9--