Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:90238 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 16490 invoked from network); 6 Jan 2016 21:22:45 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 6 Jan 2016 21:22:45 -0000 Authentication-Results: pb1.pair.com smtp.mail=danack@basereality.com; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=danack@basereality.com; sender-id=unknown Received-SPF: error (pb1.pair.com: domain basereality.com from 209.85.220.175 cause and error) X-PHP-List-Original-Sender: danack@basereality.com X-Host-Fingerprint: 209.85.220.175 mail-qk0-f175.google.com Received: from [209.85.220.175] ([209.85.220.175:34179] helo=mail-qk0-f175.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id A2/81-21755-4A58D865 for ; Wed, 06 Jan 2016 16:22:45 -0500 Received: by mail-qk0-f175.google.com with SMTP id h11so22103231qke.1 for ; Wed, 06 Jan 2016 13:22:44 -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:content-transfer-encoding; bh=IGLtQ3EmIMNtMh23E/CkjFzT0ZME4Jnwr3iH8jo9OB0=; b=BnhCo65spVvQXDMIAyRxWiITXjIWvNYX7XLBJjKdYlzQL39U/nVLfgO2G7j5gHjiBG LNE913K2DVnnytm0wGilCIgf5CJSJU84YAtKGeZNR4bD7aL/17fgycna5jJJjAXWmq9N J7k5aYmAnjIX/2pnNuGsv/WjXsW5nDwe0oagaMCVtWBhZ5f/B6xqmsg8h7BPhegBM2AZ Lb9Qs8eXT8HmyKSIbR8QPo8phWm+KbCzMwA8RilFZ9qKMNqCkrmi6NcKNebJnZBhN7H3 y2vBamVTaSNr0qSkWZVbcVO3PqJglywtnZaSAACxLdqQX9qKKnuzj4lBotttM5TBWJx/ 4Maw== 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 :content-transfer-encoding; bh=IGLtQ3EmIMNtMh23E/CkjFzT0ZME4Jnwr3iH8jo9OB0=; b=Q25aw2vesH3moNtKPf8oabb4EfEDqddBta7vTrf1+o2/kA4DnsuBXIpCSQrbTiU8xC eiz+EzQerUwm12fpWKGe0tHJAYJr1OFqhiVl9BVBLj7yeTypnFpwy5iZi+ndbaVxa8ig JyfH7j4DdePp5MVjtSqMtCeH3VMHDuIJ6PZeBsIo0u97ZKguqiqQU6GWjhXZ15LxJ3xC yDMpgBYvLHW/svFuEEJc8HztrYSJGW169r4Q9oQMN+1588qICmz/FfZ91M4XXRaLpyY0 ac91AuyfXUGZ3P5xAOEoPoLPrKqFAL77E54/tAFeJgo6vuKltoXyFEiYxf8T3IwAmVgL TcdA== X-Gm-Message-State: ALoCoQnxxfZs5QTXV1/Rd2H9BudN7qFHs68Gq6s+vsyUfNQwdblOwwp8P3X8NauqDapduZZ10lwrXlrdl3HzUcrlIWEt/NN5Qw== MIME-Version: 1.0 X-Received: by 10.129.81.136 with SMTP id f130mr42824567ywb.252.1452115361392; Wed, 06 Jan 2016 13:22:41 -0800 (PST) Received: by 10.37.83.131 with HTTP; Wed, 6 Jan 2016 13:22:41 -0800 (PST) X-Originating-IP: [2.99.239.242] In-Reply-To: References: Date: Wed, 6 Jan 2016 21:22:41 +0000 Message-ID: To: Ryan Pallas Cc: Junade Ali , "internals@lists.php.net" Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] Deprecation of the Error Control Operator (@ symbol) From: danack@basereality.com (Dan Ackroyd) On 6 January 2016 at 18:55, Ryan Pallas wrote: > Hi Dan, > > having the function name as a string will make it harder to find in an ID= E > since go to definition won't work (and since functions aren't first class > citizens as in javascript, we can't pass a raw name AFAIK) Yes, this is a limition of PHP currently. As it does keep coming up I think this is something that needs to be addressed, but would need to be done in a separate RFC. For this particular case, I don't think it should be a problem. The IDE should be able to know that the handler is a callable as that is the only thing that would be allowed there. > And what is the benefit of having either of these options being part of t= he language Er......I don't think implementing it in userland like you sugggest is workable. It would mean calling code would look like: tryAndSuppress('mkdir', ['/path/to/some', 0755, true], ['IOException']); $fh =3D tryAndSuppress('fopen', ['/path/to/some/file.ext', 'r'], ['FileNotFoundException']); for almost all code, which looks horrible, and breaks all static analysis t= ools. > in one place I need to suppress FileException and somewhere > else I don't want to. If/when I write this up as an RFC, I'm going to suggest having two built-in functions that make it easy and safe to do the normal things that code does over and over again; convert a generic exception type to a more specific one, and suppress certain exceptions. See below for outline implementations of those two functions. > Someone comes along and changes the fooRaiseException > function and now the place where we need to know about FileException we n= o > longer do. I know what you mean, but the same is true of all code that is not called directly. For example in routing for HTTP applications, the routes are setup and then called dynamically. Yes, if someone changes what the code does in the callable, then what the application does changes. Additionally with the 'suppress' and 'convert' function below, then most people shouldn't need need to use custom functions. But also, in general, I think it's a mistake to limit the power of a programming langauge to make in universally safe to use. At least to some extent, if a feature can never be misused, then it's probably not powerful enough. Stuff needs to be safe to use by default, but if people want to do crazy stuff, we shouldn't delibrately stop them aka =E2=80=9CYou can't give her that!' she screamed. 'It's not safe!' IT'S A SWORD, said the Hogfather. THEY'RE NOT MEANT TO BE SAFE. 'She's a child!' shouted Crumley. IT'S EDUCATIONAL. 'What if she cuts herself?' THAT WILL BE AN IMPORTANT LESSON.=E2=80=9D =E2=80=95 Terry Pratchett, Hogfather cheers Dan This is some example code, that uses the suppress and convert functions below to suppress any IOException raised by mkdir, and then convert and IOException generated by file_put_contents into a SavingDataException function saveData($directoryName, $data) { // If the directory already exists, that is mkdir($directoryName, 0755, true) raise suppress("IOException"); // Actually write the data. Failure to save gets converted // into a SavingDataException file_put_contents($directoryName."/foo.txt", $data) raise convert("SavingDataException", "IOException"); } // Returns a closure that suppresses any exception that matches // the listed types. function suppress(...$suppressedExceptions) { $fn =3D function (\Throwable $t) use ($suppressedExceptions) { foreach ($suppressedExceptions as $suppressedException) { if (is_a($t, $suppressedException) =3D=3D=3D true) { return; } } throw $t; }; return $fn; } // Returns a closure that converts all exceptions that are listed // into a new exception of the type '$newException'Type with the previous // exception set as the 'previous exception'. function convert($newExceptionType, ...$exceptionTypes) { $fn =3D function (\Throwable $t) use ($exceptionTypes) { foreach ($exceptionTypes as $exceptionType) { if (is_a($t, $exceptionType)) { throw new $newExceptionType( $t->getMessge(), $t->getCode(), $t ); } } throw $t; }; return $fn; }