Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:90208 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 56921 invoked from network); 6 Jan 2016 17:12:40 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 6 Jan 2016 17:12:40 -0000 Authentication-Results: pb1.pair.com header.from=danack@basereality.com; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=danack@basereality.com; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain basereality.com from 209.85.160.181 cause and error) X-PHP-List-Original-Sender: danack@basereality.com X-Host-Fingerprint: 209.85.160.181 mail-yk0-f181.google.com Received: from [209.85.160.181] ([209.85.160.181:34162] helo=mail-yk0-f181.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 97/C5-21755-70B4D865 for ; Wed, 06 Jan 2016 12:12:40 -0500 Received: by mail-yk0-f181.google.com with SMTP id a85so244821203ykb.1 for ; Wed, 06 Jan 2016 09:12:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=basereality-com.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=+SezDaE8VUVrawIDndRLQa1iNJlV7yiCyruqtUbyK/4=; b=nCtWkkpGgtf4bhSNHQAaPMiKI8iZKSIcZJmXmJy+Cu3oGk4jo8MJ57tTPi9ShJPNjc t43rGsFGSX3ACXW+mk7VpG82A5tkcHgqViKGswmM94rVsRgQLt7e5qRKr4tE1dywJy3U MF7qizRRH6Fwv19GSHhLG5cjT06xjE3v/DVfdpgwOgmVxigPWnRLL6YmsnsMN4L91CN3 OrjNympikaofbLYC3feoiwPACH+RaLh8JMz16EEKVgU2L976gPe6aId88MF56Nb+gdM4 r/enl5J5nvOTBQGqaKy3UNz3leXZDWelvMzaGAfjiZI1JmTT7uL6Ea6ITE1b3uW5qYCf 7l6Q== 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=+SezDaE8VUVrawIDndRLQa1iNJlV7yiCyruqtUbyK/4=; b=df6ICkYjf0j4ls6vkhTuqdRuNcjSUZrrI2Recd86/CiyUf1DaMEou/TUHe6OltB2RP w4jbPATczsCISEK+8S57qRL1kShviLaKLN0jGk4NNhnOJgkcUvd0AfyPyvt45U7tpNcb MjYWXfwdgxB4sNRSuIGL4smBNnLPPq76cFyOA4rbIKeohqcjxFnJtqeHiERn/Vp35A+e auC9jPCZGgv3lti1CHmht+cH7F3haZbOJniqOmwxuBuaAA67pG0CRX8qsC/xpgHN0z8E Xooe0h9OeOO2AxGI/9qP3vCLSAI9PzmoAcMhQkYj0IOhmaFk6TZP3Ueoyb2PPp/ORXlj 2FWQ== X-Gm-Message-State: ALoCoQnMfMG+JPtueMYpAGYH47D8qzFc+wC9iupoCH0KvgqR9BQCBPBoToIAiC3mqgoYvkmg0eRcl32aczfIJ+rADvdf6VEeTQ== MIME-Version: 1.0 X-Received: by 10.129.29.14 with SMTP id d14mr66487878ywd.182.1452100356036; Wed, 06 Jan 2016 09:12:36 -0800 (PST) Received: by 10.37.83.131 with HTTP; Wed, 6 Jan 2016 09:12:35 -0800 (PST) X-Originating-IP: [2.99.239.242] In-Reply-To: References: Date: Wed, 6 Jan 2016 17:12:35 +0000 Message-ID: To: Junade Ali Cc: "internals@lists.php.net" Content-Type: text/plain; charset=UTF-8 Subject: Re: [PHP-DEV] Deprecation of the Error Control Operator (@ symbol) From: danack@basereality.com (Dan Ackroyd) On 31 December 2015 at 14:52, Junade Ali wrote: > Hi all; > > I am looking to submit an RFC in order to remove the error suppression > operator in PHP, namely the @ symbol. > Hi Junade, TL:DR - I think just deprecating the silence operator without having a plan for something better is not going to happen. The below summarizes/repeats what has been said already, and suggests an alternative. ------ So, the problem with the silence operator isn't that it exists, it's that it silences all errors. @foo(); bar(); This silences all warnings/errors raise by the function 'foo'. Which is bad because the programmer probably only meant to silence a specific error or warning. Converting all the internal warnings and errors to exceptions without doing anything else is probably not a great idea. Say that foo has two error conditions which get changed to be two exceptions FileException and DNSException. The code would now look like: try { foo(); } catch (FileException $fe) { // This is not an error in this situation, execution can continue. } catch (DNSException $ne) { // This is not an error in this situation, execution can continue. } bar(); That is pretty horrific even with just two exceptions. In actual code, it would be even worse when there are multiple lines that need errors supprssing. To make it be acceptable, I think what is needed is somthing like the ability to supprress individual exceptions on a single line. // If FileException, NetworkException are thrown inside 'foo', // they are automatically // caught and execution continues to call bar() foo() suppress FileException, NetworkException; bar(); That would allow people to ignore specific exceptions without having a huge amount of boilerplate code that makes the actual code illegible. Possibly a more powerful technique would be needed, e.g.being able to specific an exception handler on a line by line basis.* // Execute function foo and if any exception is // raised, call the callable 'fooCallException' foo() raise 'fooRaiseException'; bar(); public function fooRaiseException(\Throwable $t) { if ($t instanceof FileException || $t instanceof NetworkException) { // This is not an error in this situation, execution can continue. return; } // Other exceptions are not acceptable. // Propagation of the exception should continue as normal. throw $t } The benefits of doing it like this are: * Any unexpected exceptions are not silenced. This avoids the problem of all errors being silenced when the programmer thought only a single one would be suppressed. * It would allow users to debug their code. Even if an error is suppressed by the raise callable for a line of code, it would still be userland code that can be stepped through with a debugger, and so you can see the exception inside the 'raise' function. * It leaves the code in a readable state, which having lots of try/catch blocks does not. * It allows separate modules to have their own way of handling errors, whereas set_error_handler is a per application setting. As I said at the start, I think we need to have more powerful error handling in place before deprecating the silence operator. If anyone wants to progress this RFC, what I think needs to happen is: * Work on something like the above 'raise' or 'suppress' exceptions so that there is an alternative to the internal warnings. * Work on a plan on how to migrate all internal errors/warnings to individual exceptions. The current way of using set_error_handler to convert warnings/errors into generic exceptions isn't good enough. People need file operations to raise a more specific 'FileException', to allow catching of individual types of error. I don't think it would be feasible to just have a massive BC break on this...so a cunning migration plan would be needed. * Figure out if the silence operator is then no longer needed when those two are done. Obviously the removal of the silence operator could only be done at a major version, however adding the individual 'raise' handling or allowing users to convert internal warnings/errors to specific exceptions could be done at minor versions, and probably should be, if you want to be able to plan to remove the silence operator for PHP 8/9. cheers Dan * This would be similar to Pythons 'temporarily suppressing warnings' but instead on a line-by-line basis rather than function basis. https://docs.python.org/2/library/warnings.html