Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:107619 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 65734 invoked from network); 22 Oct 2019 00:13:24 -0000 Received: from unknown (HELO php-smtp3.php.net) (208.43.231.12) by pb1.pair.com with SMTP; 22 Oct 2019 00:13:24 -0000 Received: from php-smtp3.php.net (localhost [127.0.0.1]) by php-smtp3.php.net (Postfix) with ESMTP id 34F2E2C2E08 for ; Mon, 21 Oct 2019 14:59:09 -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-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) (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 14:59:08 -0700 (PDT) Received: by mail-wr1-x42c.google.com with SMTP id c2so10433895wrr.10 for ; Mon, 21 Oct 2019 14:59:08 -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=aFXng7nluc/VhzGJiXbt2ehTkMOqlUp/0biYwVRXE34=; b=m6ZSvu1H3PbupGsE3pC+ZOakSEYMiiySjb8aUnzkgo0CWRKRSWa+pTXT+IuSNeqNyM gsG07nw1o+SoE41A2fv0Ep1Ke+paTt9sivwgnsE4N1KDCLEFGKnyhbfo29SIUX6VZTXS 2v9zFsQ2h0JQrZpsG5Uiym4lIdynKO2ijb8itm/3kJMIK67Kr9HkAMh6vOzcn0DVv6nI 6sDCYDTLZbAp0u1cL+b/Q0j6ZpSgKbKD+9goZTuPDp2ZGJ41AQBEtuzPhggmMlFykK2q VNUGRprkSQNkA7hlxGtXen+ltc8H73Evdm0EDeB0B7zkefoaYL2lGtXJJjkLfEgaUygq da6Q== 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=aFXng7nluc/VhzGJiXbt2ehTkMOqlUp/0biYwVRXE34=; b=TounhQw+E5lu50KI3zdMMIXtxi4pIwWSp3C57FGKeJg741GI8wvSNHIKHrgp6SQGgE BoXKHEZCB0hhoByKINXWyM9imkqJgGwIOuyxRG11JWhI3Iaws6tLA/kmyT/spQPkSLni DT5RAF1ODWbPkRTrekJkjHF0jCtw7BvsiqHuxL8qZ443gawA9aTzE+JLgs6PTdtvKJJN SWnPiLJHuz+Ga7otYZ+VmO/4aVNrFoJ3ByUEoXKi9Boji8Q6sOGJPRHGNH7Mq+eBdrKR OtIDN2LJwkSWRxee0obpU31SwiCu+W9n7PNuQBVkkavVIrMoHEhANjWyiKsYiHa8gzHg VSxg== X-Gm-Message-State: APjAAAW0ZsTEoWGUo7JjPqF2I4woC0R4IqkNaKpkgYWRM+x+cXkqGe/g IJJy+am0Mz9JQJlyDL8v0DhJlA/huH4= X-Google-Smtp-Source: APXvYqw0kqgM6fX9CwiV7JALfPjE59VcFNQRgpjfLJB9nE+uL+hzUDSZrdyYt8t4UfikUVdIimn77Q== X-Received: by 2002:adf:94e2:: with SMTP id 89mr303471wrr.259.1571695147192; Mon, 21 Oct 2019 14:59:07 -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 b5sm14539433wmj.18.2019.10.21.14.59.05 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 21 Oct 2019 14:59:06 -0700 (PDT) To: PHP internals References: <6fa02cb5-b474-4b36-4e0f-89679475e250@gmail.com> Message-ID: <9c1795d1-a069-f1b5-686c-7d53e39e1033@gmail.com> Date: Mon, 21 Oct 2019 22:59:03 +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 21:38, Benjamin Morel wrote: > Sure, you can do without exceptions. I think what you're suggesting is > similar to Go's error handling. But PHP at some point decided in > favour of exceptions, so it would be logical to pursue in that direction. I didn't say "do without exceptions", I said "use exceptions when they're the right tool, and other tools at other times". > I would classify most, if not all, filesystem-related functions as > mostly "yes, do stop execution by default when something fails". So > this is, as well, in favour of exceptions. You've backed that up with exactly one example function, and immediately concede a case where you might want a non-exception flow. Here are a handful more examples off the top of my head: * Attempt to atomically lock and open file, returning either a file handle or a "could not lock" status. * Attempt to read from a file, terminate loop when the file handle reaches EOF. * Attempt to delete file, ignore if it doesn't exist. All of these are candidates for returning false, or an error code, or an object in a particular status. They could be handled with exceptions, but that would force common patterns to use exceptions for flow control, which is generally seen as a "bad smell". > Handling each and every error manually by using the return value > requires a lot of discipline, which could be a very steep learning > curve for PHP developers used to a fast prototyping language. Again, I am not saying that every function should have a complex error-handling system. It may well be sensible to have a function for "open file, I don't expect anything to go wrong" which throws an exception, and a separate one for "try to open file, and report the result without ever triggering an exception". That's the point of designing a new API, to work out what the use cases are, and cater for them in a clean way. Regards, -- Rowan Tommins (né Collins) [IMSoP]