Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:82946 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 85275 invoked from network); 17 Feb 2015 11:57:46 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 17 Feb 2015 11:57:46 -0000 Authentication-Results: pb1.pair.com smtp.mail=rowan.collins@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=rowan.collins@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.48 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 74.125.82.48 mail-wg0-f48.google.com Received: from [74.125.82.48] ([74.125.82.48:36518] helo=mail-wg0-f48.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 91/00-19463-8BC23E45 for ; Tue, 17 Feb 2015 06:57:45 -0500 Received: by mail-wg0-f48.google.com with SMTP id l18so31697360wgh.7 for ; Tue, 17 Feb 2015 03:57:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type:content-transfer-encoding; bh=2SjncDDsTwbX4PmCkmh6YZi0IsNrWJG9/mcsidUSy0Y=; b=sgpCVfjcjaRve3F58br6uEVzChc2cnSibaGxe7UgvNvnH4YHydnVRXng77lCs6HPtH mjzRnQ5G9twB6Bv+NNxZT6QlAnoA1pl0tpH3LowMMBw7+U8lkdgOX0ESF5zH6pf+yjRe ac8HYNrKbANtEzxYp9RQR/jL0imlGE+PcVsEoi096pE9Jcg74zEiLuNCL6lyDVU4X5GG IVgmXOsLH74ubYxAIEICNW76J1TbINdXcb9xWjZXne371scejnjpR9R1dGj7TvCERTns CYO2Tk5FhE6AIHxyEA7RraTZoeYCZDeMczW2m6WxHbdvZKgf4vScDsVjg7ds6jZghBbV sYQw== X-Received: by 10.180.198.37 with SMTP id iz5mr45515800wic.95.1424174261374; Tue, 17 Feb 2015 03:57:41 -0800 (PST) Received: from [192.168.0.172] ([62.189.198.114]) by mx.google.com with ESMTPSA id ub1sm27031873wjc.43.2015.02.17.03.57.39 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 17 Feb 2015 03:57:40 -0800 (PST) Message-ID: <54E32CAA.5030600@gmail.com> Date: Tue, 17 Feb 2015 11:57:30 +0000 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.4.0 MIME-Version: 1.0 To: internals@lists.php.net References: <54E12349.7070806@gmail.com> <16.9B.05176.AE1C1E45@pb1.pair.com> <54E1C993.1070609@gmail.com> <37.20.01961.31113E45@pb1.pair.com> In-Reply-To: <37.20.01961.31113E45@pb1.pair.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] [RFC] Exceptions in the engine From: rowan.collins@gmail.com (Rowan Collins) Tony Marston wrote on 17/02/2015 09:59: > "Rowan Collins" wrote in message news:54E1C993.1070609@gmail.com... >> >> Tony Marston wrote on 16/02/2015 10:09: >>> This RFC only mentions errors with object methods, so what impact >>> would it have with procedural functions. For example, if >>> fopen('nonexistantfile.txt') fails the return value is FALSE and an >>> E_WARNING is generated, but it is difficult to trap the error >>> message (it could be a permissions error, for example). Is there any >>> plan to convert procedural functions to throw exceptions? >> >> As Nikita already said: >> >>> This RFC is strictly about fatal and recoverable fatal errors. >>> Changing any >>> other error types to exceptions would be a significant >>> backwards-compatibility break. >> >> So, no, since that's currently an E_WARNING, there is no current plan >> to change that case to an exception. If we were writing fopen() from >> scratch now, it might be worth considering, but the BC implications >> of changing something from non-fatal to fatal are rather drastic. >> >> That has absolutely nothing to do with OO vs procedural code, though. >> A procedural function could well have an error condition which should >> be fatal if unhandled, but can usefully be caught somewhere up the >> stack, which is basically what an exception is for. Any procedural >> function which currently issues an E_ERROR or E_RECOVERABLE_ERROR is >> a candidate to be converted under the current RFC. >> >> Regards, > > The reason that I mentioned this problem with fopen() - the difficulty > with capturing the error message if it fails - is that it also exists > with some other functions as well, so it would be nice to be able to > put the function in a try ..... catch block so that any and every > message could be made available. It is quite obvious that changing > fopen() to use exceptions would be a major BC break for all exiting > applications, so my question is this: > > Would it be possible to tell the function if it were being called in a > try ... catch bloc or not? If it were then throw an exception, if not > then don't throw an exception. I realise that this might be tricky to > implement, but if it could be it would allow the developer to choose > whether he/she wanted to use exceptions or not instead of having the > choice forced upon him/her. > > Is this possible? Or am I just dreaming? The point of exceptions is that they don't have to be caught in the current scope. So is the below fopen() call "in a try ... catch block" for the purposes of that check, or not? If putting try { ... } around an entire application caused all calls to fopen(), in every library it used, to stop returning false, you'd have exactly the same BC issue as just changing it permanently. function foo() { try { $data = load_data(); } catch ( ... ) { ... } } function load_data() { $fh = fopen(...); ... } So no, I'm afraid it's probably not possible. Regards, -- Rowan Collins [IMSoP]