Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:61697 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 47204 invoked from network); 24 Jul 2012 17:01:18 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 24 Jul 2012 17:01:18 -0000 Authentication-Results: pb1.pair.com header.from=nikita.ppv@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=nikita.ppv@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.217.170 as permitted sender) X-PHP-List-Original-Sender: nikita.ppv@gmail.com X-Host-Fingerprint: 209.85.217.170 mail-lb0-f170.google.com Received: from [209.85.217.170] ([209.85.217.170:63654] helo=mail-lb0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id C4/D0-42538-CD4DE005 for ; Tue, 24 Jul 2012 13:01:17 -0400 Received: by lbgc1 with SMTP id c1so10295578lbg.29 for ; Tue, 24 Jul 2012 10:01:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=JiUCNN1lG/qVYbJ0/a9+SSFm2Ela/DFD0lE9DBiyE/o=; b=RnlZSGLzu692+VJN/SEs1jsiPAwz6iNMxvxCfkI6xZqQC2UzLiBgpZ4re/qDQSAVbB i2Z/3+rmHKq3WnCi9F9bp/sZGtqwbLH1XGtN4NUGpY9xCmyPAQLAs5ciIExVnL0v8YYl R2ynK+xfaFaAs/ONzUc6VV18XDTqfOlJ3d15pyXdV483LMNQGzZi7cLauSIgmo5rKlIf Sde/7G0DGhauBz7KqNUrHHbQQiqyuNFH6F/G5U5GKIlUMtnEul1bcKybxSNmqRrEhO++ Bc+1hN5TjG5pyOZaZLxjPIREOTzBpqt2qnyEACyS6Rq1csi1G+aRdB2n63ZopyjH71Mr APhA== MIME-Version: 1.0 Received: by 10.152.132.40 with SMTP id or8mr22431961lab.24.1343149273091; Tue, 24 Jul 2012 10:01:13 -0700 (PDT) Received: by 10.152.114.70 with HTTP; Tue, 24 Jul 2012 10:01:13 -0700 (PDT) In-Reply-To: <500EBC47.2080200@lerdorf.com> References: <500EBC47.2080200@lerdorf.com> Date: Tue, 24 Jul 2012 19:01:13 +0200 Message-ID: To: Rasmus Lerdorf Cc: Laruence , PHP Internals Content-Type: text/plain; charset=ISO-8859-1 Subject: Re: [PHP-DEV] [RFC] Supports 'finally' keyword for PHP exceptions From: nikita.ppv@gmail.com (Nikita Popov) On Tue, Jul 24, 2012 at 5:16 PM, Rasmus Lerdorf wrote: >> The finally clause comes with a very strong promise that the code in >> the clause will run in absolutely any case (short of sigkill, maybe). > > No it doesn't, at least not in Java. A fatal Java error or an explicit > call to System.exit() will cause the finally clause to not be executed. > It is a simple exception-level construct and doesn't in any way promise > to be called in a fatal error situation. And regardless of what Java > does, we are free to define it and provide whatever promises we want > here, but keeping it in line with Java's implementation makes sense to me. I was writing this out of a Python perspective, which gives strong guarantees for finally. Java indeed reserves the right to not run finally if System.exit is called. Still my point stands. If fatal errors and die are not handled by finally the feature does not make sense to me. You simply can't do any kind of remotely important cleanup in there (like releasing locks etc). Please don't forget that in PHP a lot of stuff throws a fatal error. Some simple oversight like calling $foo->bar()->baz() while $foo->bar() can also return false or null can lead to a fatal error that's easily missed during testing. Similarly die; is commonly called in code doing header redirects. I think it would be unacceptable to not run cleanup clauses in that case. Another, separate point against finally is that in PHP (unlike many other languages) most (all?) built-in resources clean up after themselves. So if you open a file you don't have to worry about closing it again. It'll do that all by itself as soon as it goes out of scope. The same applies to database handles, etc. As PHP uses refcount based garbage collection the resource is actually cleaned up right away, not just at the next GC run (which could be problematic if you open up many files in a row). Nikita