Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:107612 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 2171 invoked from network); 21 Oct 2019 21:00:37 -0000 Received: from unknown (HELO php-smtp3.php.net) (208.43.231.12) by pb1.pair.com with SMTP; 21 Oct 2019 21:00:37 -0000 Received: from php-smtp3.php.net (localhost [127.0.0.1]) by php-smtp3.php.net (Postfix) with ESMTP id 291FF2CFC3A for ; Mon, 21 Oct 2019 11:46:20 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp3.php.net X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: X-Spam-Virus: No Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by php-smtp3.php.net (Postfix) with ESMTPS for ; Mon, 21 Oct 2019 11:46:19 -0700 (PDT) Received: by mail-wm1-x335.google.com with SMTP id p7so14513799wmp.4 for ; Mon, 21 Oct 2019 11:46:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding:content-language; bh=JS3AE1bFqYlTAhJnnbk0cHebwgxnkXSXzKeQAc7xxMk=; b=emwVPNJOyTs6oIJ9C/yIN3OW1jWXRbjum0nqQJRHAIW/99a7qxLw/fvmCO9AaHQTWV 1IW4SiWe4C8MRuJtQLh4Y6U6lfLm556UWKjEP3yhxa1oYLQY3S9teE18z7yRU8OfpyRZ E/2w7DmBuG+yYM6N5V289sdiNH1zpnZitmQQpDvqDRUN/X+tFT1n3h657Iv9QYX//vk4 9Ci+t3XSkd1JsbRswsKoF4ajcdeVw3ntGoEdE8gibdKaGHLKWJt5VrlMYatI2YSpOJZC W4RJTX3Dycc9nJn8FZJx/kazSXjqvc35vRHIkAuxAtm5OlEll4vnIZYWLTZEJWib1QZa bNIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=JS3AE1bFqYlTAhJnnbk0cHebwgxnkXSXzKeQAc7xxMk=; b=YNqd/WPz9BW4fLeFYBuV4750B2XRq/bq9cK0KiNJO73+CeEaTNh7kW3xW5khVqZ28F nVxTPO9EjwTRghL9KyVo7xxc/vGiAlkB2VnGxXCasWzFyrQqjECSRCVZtqJhLlmB1w+y fMtIfTTHM3us3257vNznI70qVtr7voiJL95ddFgwKOMBDFlTJxhRjgPpP6rh9Ogb8+FO cuZ1iMNas1LD5dqOTvrC1upTr9ouwoX79J5ljKWyYsj1Fpo9J+/MT47lL4j4G7ybUQuK F/O/vMzUDRaXH2b4ONoAp+be1cXDuXYMT4/F7ttzOM2Zg6lQAndBdgDga37jNJgd4LF1 /+OA== X-Gm-Message-State: APjAAAVv1OV5WvcVNDZT4z3sYSWT5lhoZjOVyt0xg+yxwwPqhqPNh2MQ mGMTfJzasJWekYZaMZYaamsvnuKjXHY= X-Google-Smtp-Source: APXvYqxZYHiduMxNwHptbFENKqlVqGMrjwXVJ8LZuHWOWeMIJaWgmIJnW5ivh73rN3gaQsS10fanYQ== X-Received: by 2002:a1c:750d:: with SMTP id o13mr19843093wmc.140.1571683578134; Mon, 21 Oct 2019 11:46:18 -0700 (PDT) Received: from [192.168.0.16] (cpc84253-brig22-2-0-cust114.3-3.cable.virginm.net. [81.108.141.115]) by smtp.googlemail.com with ESMTPSA id p21sm6740327wmc.25.2019.10.21.11.46.17 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 21 Oct 2019 11:46:17 -0700 (PDT) To: PHP internals References: Message-ID: <6fa02cb5-b474-4b36-4e0f-89679475e250@gmail.com> Date: Mon, 21 Oct 2019 19:46:15 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.9.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-GB X-Envelope-From: Subject: Re: [PHP-DEV] Reclassifying some PHP functions warning as exceptions From: rowan.collins@gmail.com (Rowan Tommins) On 21/10/2019 18:45, Benjamin Morel wrote: > I personally like exceptions in all cases, as they allow for > fine-grained error handling, for example: > > ``` > try { >     mkdir('somedir'); > } catch (FileExistsException $e) { >     // only catch *this* exception, which my program expects, >     // let any other exception (say a PermissionException or a generic > IoException) bubble up! >     // this *is* what you want: it will be caught by your top-level > exception handler which will log it to inform you that something is > wrong with your system > } > ``` I think this argument is something of a logical fallacy: just because exceptions are (or can be) more fine-grained than the current return value, that doesn't mean they're the best tool for the job. If I'm remembering it correctly, an example is the old PEAR error-handling model, where rather than false, functions returned a PEAR_Error object. This could be just as fine-grained (using sub-classes or error code constants) as an exception, but without the additional behaviour of blowing through the stack. In some cases, you can go one step further, and have a "result" object, with methods like isSuccessful(), getErrorCode(), and getOutput(). Importantly, this can and should be different for different functions. In a previous message you wrote this, which I think mischaracterizes / misunderstands previous discussions: > To play the devil's advocate, however, IIRC some discussions in the past > mentioned that the BC breakage that comes with it is such an issue that it > would be preferable to create a brand new API rather than attempting to fix > the existing one. > Nobody ever jumped in to propose such an API, though :-( It's not that we need "a brand new API", singular, it's that some of the more complex sets of functions should be redesigned, with error handling considered as part of each design. So, a new file-handling API could provide a much richer set of error codes for its equivalent of fopen(), which might or might not involve exceptions. It might instead have a file handle object which could represent closed and errored handles, so that attempting to open a file would always give the same result type, but would have information about what failed. Meanwhile, if we were to design a new string API to make things more consistent, and perhaps introduce better Unicode support where relevant, that would be a good chance to throw exceptions for truly exceptional cases. However, we might also include more forgiving variants of functions, for "best effort" processing of user input (like iconv's //TRANSLIT and //IGNORE modes). On the other hand, there are some errors where the answer to the question "would it be better to halt processing than continue in an unknown state?" is "yes", so it's reasonable to introduce an exception, even though existing programs aren't expecting it. But again, this should be considered for every case, not as a general rule that all Warnings should be promoted. Regards, -- Rowan Tommins (né Collins) [IMSoP]