Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:90365 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 61928 invoked from network); 8 Jan 2016 16:53:47 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 8 Jan 2016 16:53:47 -0000 Authentication-Results: pb1.pair.com header.from=rowan.collins@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=rowan.collins@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.41 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 74.125.82.41 mail-wm0-f41.google.com Received: from [74.125.82.41] ([74.125.82.41:36387] helo=mail-wm0-f41.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id FE/B0-55593-B99EF865 for ; Fri, 08 Jan 2016 11:53:47 -0500 Received: by mail-wm0-f41.google.com with SMTP id l65so141903274wmf.1 for ; Fri, 08 Jan 2016 08:53:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=subject:references:from:to:message-id:date:user-agent:mime-version :in-reply-to:content-type:content-transfer-encoding; bh=BvJxygVdCB5mecW2P/XPh6NWZPo7d97SVF+8Qf9o+oM=; b=e3V+jAwz8yW/B9O6wMILZH0XIXLKv1CCyZ+UEecPeltdL2tED99hX6Y3AsWELThNK+ B9RtKYZVXJrWdQYQ+fvY4DW5OWI67O2B2CWn2x2erE2pMSQ+ihyfFiKwvXSH3VLNJhGc jxoZSJ5n9ALqBQD3SdO//Fw8FR0bvhkyZPnEkfCLdHrZazEmtJabylXkCmSer0aGzpPa YKixTRrOlapBro/4ltWQ5wc2Twnzm/vs1w1pGTyXRmeNifjO2EkDNbf44GfeU4xu040K PZAtsn2sqciUAhd2Tj3J1nkx6rhBNFTdslh+HPPcisBRttLuJkkV4JValO1QoUySDx0K WFiA== X-Received: by 10.194.88.10 with SMTP id bc10mr123351920wjb.49.1452272024393; Fri, 08 Jan 2016 08:53:44 -0800 (PST) Received: from [192.168.0.137] ([93.188.182.58]) by smtp.googlemail.com with ESMTPSA id g187sm19366064wmf.8.2016.01.08.08.53.43 for (version=TLSv1/SSLv3 cipher=OTHER); Fri, 08 Jan 2016 08:53:43 -0800 (PST) References: <568FDA4B.60005@gmail.com> To: "internals@lists.php.net" Message-ID: <568FE92D.4090001@gmail.com> Date: Fri, 8 Jan 2016 16:51:57 +0000 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.5.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Deprecation of the Error Control Operator (@ symbol) From: rowan.collins@gmail.com (Rowan Collins) Dan Ackroyd wrote on 08/01/2016 16:26: > On 8 January 2016 at 15:48, Rowan Collins wrote: >> It doesn't do anything to help Stas's example for instance: >> >> @$counts[$item]++; > I think that that code is bogus since the release of PHP 7, which made > it trivial to not use the error suppression for this case, while still > writing code that doesn't take up multiple lines. > > $counts[$item] ?? $counts[$item] = 1 ?? $counts[$item]++; It's a matter of code style; to me, that's still just noise. If I know that $counts is being used as a "hash" (arbitrary keys, defined on demand) and not a "struct" (pre-defined keys, accessed dynamically) then the first version does exactly what I want it to, and I see no advantage in making it more complex. >> This is not something which should ever throw an exception, > Oh yes, it definitely should: > > $item = new StdClass; > @$counts[$item] = "This is a bad use of error suppression."; > > There is no insertion, because arrays don't support object keys. The > operation completly failed and so there should be an exception. > Currently that code fails silently. OK, fine, let me reword that: the warning "undefined index 'foo'" should never be thrown as an exception. I am absolutely not saying that there aren't cases where we should be throwing Exceptions (or Errors, now they exist) rather than Warnings, just that there are also cases where warnings are non-fatal, and have nothing in common with Exceptions. The point of the example is not that the @ operator is perfect here, it's that sometimes, the ability to suppress specific warnings as "I know and don't care" is useful. I just wanted to get people away from the example of fopen() which frankly should never be raising a warning in the first place. > I very much look forward to seeing your proposal for this file > handling API, which is both easy to use, and never throws exceptions > which people will want to discard. I detect sarcasm here, and would like to hear a non-sarcastic version of your point. Can you give an example of an operation where it would be reasonable to throw an exception, but also reasonable (and common enough to affect the design of the API) to completely ignore that exception and carry on? If an operation has fatally failed (such as trying to open a non-existent file for reading), people will want to have code handling that failure, so suppressing the exception would be counter-productive; if an operation has encountered an unexpected but non-fatal condition, it should signal that with something other than an exception (for instance, returning a success boolean or status flag). Regards, -- Rowan Collins [IMSoP]