Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:83166 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 74413 invoked from network); 19 Feb 2015 09:57:46 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 19 Feb 2015 09:57:46 -0000 Authentication-Results: pb1.pair.com header.from=dmitry@zend.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=dmitry@zend.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain zend.com designates 209.85.220.179 as permitted sender) X-PHP-List-Original-Sender: dmitry@zend.com X-Host-Fingerprint: 209.85.220.179 mail-vc0-f179.google.com Received: from [209.85.220.179] ([209.85.220.179:64565] helo=mail-vc0-f179.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 58/57-22021-893B5E45 for ; Thu, 19 Feb 2015 04:57:45 -0500 Received: by mail-vc0-f179.google.com with SMTP id hy4so770689vcb.10 for ; Thu, 19 Feb 2015 01:57:41 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=2K4hbjS5SG7UvBjQvSEMJyEi+z3QmSfg3a92W2Da14Y=; b=ZbAHYI8J0y8apWGTwxxQPYgcFwLt4k1hw3jjlE5u92fmcl+46OP+i5YpC/Kghz3y8Z OB2TXPXj125OMNKVft7HZHYTNMAcPsf680zXSWoAzryMk3KXFQuQX8RxQjm9pwcQxF0s brH6sXiurkNXEo6uD5yw23igrRm/AcSiVeVprdq+Jq48cpIne1VW500m949egv3VlVHK lZsF27QUQtPcIcMAV9RyfSGrOtV/bhlNBlnqEYWdmg4Yh4EEY5/DnKEVtrxbkgvFF2zC JGXyiGzxQxnX9REZ/lyxJlnanfTwsWxMLXlKrkhQ2QbWx/H8vhbpc49Df79LlZEr5VBl kXIg== X-Gm-Message-State: ALoCoQmgs6GDXdmYWOkkKpPXzIOPBaGis0JzwtBW7/ybbRjumEuhWnOLY27V2TY9XeLlDptC8cJHEZt0xMR7+Zd21p1RGmHkihoP+fvwozAnqLIp6ybh8kop5BCERWDKYneYHn1mLnaPh8fm74BmMUA80tbwl/shiQ== MIME-Version: 1.0 X-Received: by 10.221.44.65 with SMTP id uf1mr2202438vcb.46.1424339861889; Thu, 19 Feb 2015 01:57:41 -0800 (PST) Received: by 10.52.74.73 with HTTP; Thu, 19 Feb 2015 01:57:41 -0800 (PST) In-Reply-To: References: <54E12349.7070806@gmail.com> <16.9B.05176.AE1C1E45@pb1.pair.com> <54E1C993.1070609@gmail.com> <37.20.01961.31113E45@pb1.pair.com> <54E32CAA.5030600@gmail.com> <54E4FAC2.7060200@gmail.com> Date: Thu, 19 Feb 2015 13:57:41 +0400 Message-ID: To: Tony Marston Cc: PHP Internals Content-Type: multipart/alternative; boundary=001a11c3ea3c81ff01050f6df798 Subject: Re: [PHP-DEV] [RFC] Exceptions in the engine From: dmitry@zend.com (Dmitry Stogov) --001a11c3ea3c81ff01050f6df798 Content-Type: text/plain; charset=UTF-8 On Thu, Feb 19, 2015 at 12:03 PM, Tony Marston wrote: > "Rowan Collins" wrote in message news:54E4FAC2.7060200@gmail.com... > > >> Tony Marston wrote on 18/02/2015 10:52: >> >>> "Rowan Collins" wrote in message news:54E32CAA.5030600@gmail.com... >>> >>>> >>>> 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, >>>> >>> >>> Could it be restricted to the current scope? In your example the call to >>> fopen() exists in the load_data() function and is not in a try ... catch >>> block within *that* function, so the fact that the call to load_data() is >>> within a try ... catch block should be irrelevant as it is in a different >>> scope. >>> >>> >> If the exception is only thrown when the try - catch is in the same >> scope, is there really much advantage to it being an exception? When you're >> that close to the code, sticking an if ( $fh === false ) { ... } around it >> really isn't that much different from catch(IOException $e) { >> > > The advantage is that you can obtain the reason for the error. All that > happens with fopen() at the moment is that it returns FALSE which tells you > that it has failed, but it does not tell you why. This is a classic example > of the semipredicate problem for which exceptions were originally designed. > The main advantage is the ability to catch FATAL errors that previously leaded to script termination and 500 response. Thanks. Dmitry. > > Having the problem be detectable in a higher scope is kind of the point >> of exceptions. >> > > So is the ability of catching an exception immediately it is thrown so > that you can obtain the error message. Having the ability to deal with an > exception at a higher level is only relevant if you don't deal with it > immediately, either by design or by accident. > > -- > Tony Marston > > > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > --001a11c3ea3c81ff01050f6df798--