Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:73665 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 11793 invoked from network); 11 Apr 2014 09:39:25 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 11 Apr 2014 09:39:25 -0000 Authentication-Results: pb1.pair.com header.from=julienpauli@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=julienpauli@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.128.175 as permitted sender) X-PHP-List-Original-Sender: julienpauli@gmail.com X-Host-Fingerprint: 209.85.128.175 mail-ve0-f175.google.com Received: from [209.85.128.175] ([209.85.128.175:43631] helo=mail-ve0-f175.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id C5/E0-02145-C48B7435 for ; Fri, 11 Apr 2014 05:39:25 -0400 Received: by mail-ve0-f175.google.com with SMTP id oz11so4560651veb.34 for ; Fri, 11 Apr 2014 02:39:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc:content-type; bh=YvjECu4+hoA/H8FzIabO8qPYMVsfZ4UOdNqM4XaoR+o=; b=q7eHH4KvlChsJINRPmQC56cZf8Y11jkrRQCcXd4/x5DWADxmIN6DV41DqXX5bhkPT5 kypkOmnmfpvLrQ7xgHB/PgggO9imL3wXyHkxLdiq2MMHkW0TLqZ7bJKxuYVueljbv/2O fOXjFYVGZk0bSgMC7DIBoCvJDEc36VE410ehNtDk/E76pIaSSdoaIdnk+WazMLMVp68r d0acqLP6BGTZYUispgsHFnOm+pck3Xc49FZ+E/VM8f9CSoKuwoQtFrPBcz1a36ENHgxw MR4+w3/sIY45pMM99vw78Hga5XrlrtiNwdmEzqZTu4Tku5O3OcZ3EvzTD1l1pB65SI4p usEQ== X-Received: by 10.221.74.200 with SMTP id yx8mr18919931vcb.3.1397209162156; Fri, 11 Apr 2014 02:39:22 -0700 (PDT) MIME-Version: 1.0 Sender: julienpauli@gmail.com Received: by 10.220.81.68 with HTTP; Fri, 11 Apr 2014 02:38:42 -0700 (PDT) In-Reply-To: <5345AE83.1070506@sugarcrm.com> References: <53446FC5.7000001@gmail.com> <53459231.2080402@gmail.com> <5345AE83.1070506@sugarcrm.com> Date: Fri, 11 Apr 2014 11:38:42 +0200 X-Google-Sender-Auth: r_OU6TgmQ-28oilyVIpRZo5FCiU Message-ID: To: Stas Malyshev Cc: Rowan Collins , Marco Schuster , PHP Internals Content-Type: text/plain; charset=ISO-8859-1 Subject: Re: [PHP-DEV] [PHP.next] Error-handling using "Error Events" From: jpauli@php.net (Julien Pauli) On Wed, Apr 9, 2014 at 10:33 PM, Stas Malyshev wrote: > Hi! > >> Good point. Perhaps the real question is: what are the use cases - real >> or perceived - for the @ operator, and how, if we were re-organising >> error and message handling in general, can they best be replaced. > > There are these major use cases for using @ as far as I can see: > > 1. Shutting up noisy function because I don't care about warnings, I > just want it to do what's possible and return failure code if it's not. > E.g. - I want to json_decode some data which may or may not be JSON, if > it doesn't decode it's ok, I'll just try something else, I don't see it > to tell me what's wrong with it because I don't care, it either works or > it doesn't. I.e. the situation where if it fails, I don't care why it > failed, I just want failure code. > > 2. Similar to the previous, but a bit different twist: if I want to > handle the error myself, in some different way than outputting a string > to the screen. > > @fopen is the frequent example for both of 1 and 2. Sometimes you want > to just ignore the file if it doesn't open. Sometimes you want to handle > it, but file pointer being false is enough to catch it. Of course, it'd > be even better if you could extract the reason *why* it failed but you > often don't want it where warning reporting system puts it. Same goes > for @unlink, @include, etc. > > 3. @$foo['bar'] - i.e. get me $foo['bar'] if it's there, null if it's > not. Because writing isset($foo['bar'])?$foo['bar']:null each time is so > damn annoying. ?: helps in some cases but not all. > >>> Something like DomainNotFoundException, ConnectionDeniedException, >>> FileNotFoundException or whatnot. It's a nightmare if you actually >>> want to know what happened. >> The problem with such specific exceptions in this case is that different >> stream wrappers would want to throw completely different exceptions; I >> guess they could all extend a generic FileAccessException. > > Knowing what happened is very useful, however I don't think exception > hierarchy is a good way to keep this info. You very rarely would want to > do different things depending on why opening your file failed - was it a > disk error? permission? network problem? In any case, you probably would > want to log the error somewhere (here's where what happened is useful) > and move on (or bail out if the file was critically needed). Class > hierarchy is useless here, one class with good toString and maybe a > couple of other API methods would be much more useful. > > In general, my experience is that converting all common errors to > exceptions leads to a lot of code like: > > $success = true; > try { ... } > catch(Exception $e) { > $sucess = false; > } > if($success) { ... } > > which is plain ugly. Also, exceptions are expensive, so that would also > lead to a lot of boilerplate checking for conditions that otherwise > would be ignore - i.e. each time we try to open the file we'd have to > check if it exists and if it's readable and so on, to avoid expensive > exception. > @ actually works better in this case, but how it does it under the hood > is ugly, clunky and quite expensive too. If we could keep the agility of > @ while fixing the underlying ugliness and making the error still > accessible and useable when needed, that would be a great thing. That's the thing to do for PHP-Next. PHP-Next will be a gap in rethinking and rewriting some technical parts of the engine. Error and exception management is one part that can benefit from a rewrite. We could change things in way that they are not too error prone, and the change at user level is nearly invisible (e.g : rethink the '@' internal handling). Turning all errors to exceptions is a mistake IMHO. However, easing such a process for those who'd need it could be a great point. I'm adding the task to our wiki. Julien.Pauli