Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:107618 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 53243 invoked from network); 21 Oct 2019 23:24:46 -0000 Received: from unknown (HELO php-smtp3.php.net) (208.43.231.12) by pb1.pair.com with SMTP; 21 Oct 2019 23:24:46 -0000 Received: from php-smtp3.php.net (localhost [127.0.0.1]) by php-smtp3.php.net (Postfix) with ESMTP id 9EE5E2C43CF for ; Mon, 21 Oct 2019 14:10:30 -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=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HTML_MESSAGE,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS3215 2.6.0.0/16 X-Spam-Virus: No Received: from mail-yw1-xc2e.google.com (mail-yw1-xc2e.google.com [IPv6:2607:f8b0:4864:20::c2e]) (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:10:30 -0700 (PDT) Received: by mail-yw1-xc2e.google.com with SMTP id w140so5456112ywd.0 for ; Mon, 21 Oct 2019 14:10:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=newclarity-net.20150623.gappssmtp.com; s=20150623; h=from:message-id:mime-version:subject:date:in-reply-to:cc:to :references; bh=JMfGcMWe1ChjZr/4iX2IJ+hxlbOSjw0AB4zm1cvimXY=; b=ZEWkZla+vhBIe8SnAhWwi6y11lIUFsjJwF3V9wpVdGD5ZuCtxHI4jwbc8kF9lPxyER zuBo8MjF9om4hD6/H6K7THXtXmm/Qor25QKR5LkxumCzfCl8Nm/gN5ezuz0eUy43je0H Hhi+l6yQJKcjgozmdH6eIoApLK1eGDoBPCuelEFMoHfvknYhkAibJqYrOc35hPWfQmdN dJwAEXkKodCjoXxjeT4wrmdTcaVR9GUtjzHFZWop+eQfqFPDzaJ9ING40PZEcPqcS9LD BnoDzeIPcHmB0t6HPcLeiCG8brBYdW6s1mOyHqEePCddRfIS6xQt5Knf7xaJ20V0z43m LpOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:message-id:mime-version:subject:date :in-reply-to:cc:to:references; bh=JMfGcMWe1ChjZr/4iX2IJ+hxlbOSjw0AB4zm1cvimXY=; b=PHxDWmRCKQoGRNdMMyF4tyjpM/gQX5yW0G5mVLvigZLBaFcQ5Li9esEitDktW41530 5C50fN7zad73rRB0fRzIHZs2G2GG287Y2ePXVTCubkqhw7gpg3Pydu9q8irPGwqd6pJE yqq4twvSPofdCkPK8s+kfG4EtJgkcQar8FVOBFviegyYozO1G9BRgv5iiWc6YYtMBagD LZ1JzgGGmc2P84XeGI4Oe6UCkRRDe0uVbsKG3GbUNapKH3HGoJng4ZRsOJAubcQuDENH 0bZfl6zXMhU4NR+KtSTciU38/fX5cj+IooiJFc6iLi9ChDIxgajfC5O8+0mJdhZHgxxg DvLQ== X-Gm-Message-State: APjAAAXqSCGkP48b1QWHEUidKhkMuGJsu/d1A1Ac8c9BgncPmzpcOUr2 2k75eqS6d/2NLjXuXaDBxGdu/Q== X-Google-Smtp-Source: APXvYqyvJRtDH3XeeElBqT+DM80409XQ1PJJeW1oo14h40EM5AI2RO5uG+WKWiYDwjFEXmpEBHjzGQ== X-Received: by 2002:a81:8183:: with SMTP id r125mr665413ywf.272.1571692229477; Mon, 21 Oct 2019 14:10:29 -0700 (PDT) Received: from ?IPv6:2601:c0:c67f:e34e:90d7:91e4:da1d:b8e6? ([2601:c0:c67f:e34e:90d7:91e4:da1d:b8e6]) by smtp.gmail.com with ESMTPSA id 2sm899928ywg.43.2019.10.21.14.10.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 21 Oct 2019 14:10:28 -0700 (PDT) Message-ID: Content-Type: multipart/alternative; boundary="Apple-Mail=_0319EF5A-29F5-4803-8929-87CD551E58BA" Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.11\)) Date: Mon, 21 Oct 2019 17:10:27 -0400 In-Reply-To: Cc: Rowan Tommins , PHP internals To: Benjamin Morel References: <6fa02cb5-b474-4b36-4e0f-89679475e250@gmail.com> X-Mailer: Apple Mail (2.3445.104.11) X-Envelope-From: Subject: Re: [PHP-DEV] Reclassifying some PHP functions warning as exceptions From: mike@newclarity.net (Mike Schinkel) --Apple-Mail=_0319EF5A-29F5-4803-8929-87CD551E58BA Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 > On Oct 21, 2019, at 4:38 PM, Benjamin Morel = wrote: > Sure, you can do without exceptions. I think what you're suggesting is > similar to Go's error handling. Yes, it is like Go's error handling.=20 > But PHP at some point decided in favour of > exceptions, so it would be logical to pursue in that direction. Must we? =20 Maybe it is time to (at least) consider alternate approaches? Not to = deprecate Exceptions =E2=80=94 as many prefer to use them =E2=80=94 but = as an alternative to Exceptions for those who would prefer to use error = values instead? > 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.=20 Are you sure? Could a file system function not just as easily "stop" = and return an error value vs. throwing an exception? > To take the mkdir() example, the only reasonable failure reason I can = think > of that would not justify throwing an exception, is when the directory > already exists. >=20 > So I would be OK with this: >=20 > mkdir(): bool; // true if successful, false if the target directory = already > exists >=20 > This is, IMO, the only time we can safely proceed while ignoring the > outcome of the operation, as the filesystem is in the same state = whether or > not the function succeeded (the directory exists). All other outcomes = are, > IMO, exceptional situations, and throwing an exception is a safe way = to > guarantee that execution will *not* continue after such an error. Why must it be a thrown exception vs. a returned error object? =20 For a given application that failure might not be exceptional; the app = might have a fallback solution that want to use instead. > 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. And if people don't > strictly follow the rules, you're opening the door to a whole lot = potential > bugs in codebases. And, you miss the ability of automatic error = reporting > for uncaught errors, that you get almost for free with exceptions and = a > single try/catch at the top level. That is definitely a good argument to keep supporting Exceptions in PHP. But not an argument to make Exceptions the only approach. I have been = coding professionally for a really long long and =E2=80=94 until = recently =E2=80=94 never felt like I was happy with how I was doing = error handling, always thinking I would "get around to figuring out a = better approach."=20 Then about a year ago I started using Go, and Go's approach to error = handling just clicked for me. Go's philosophy is to handle the error as = soon as you one is aware of it and to only ever handle it once. Since I = have been using that strategy I have become very happy with my error = handling, and I now (attempt) to use the same strategy in my PHP code.=20= In PHP I now typically wrap anything that can generate an exception in = my own try_catch() function, and that function returns an error object I = can then process if an except is thrown inside. But it is visually ugly = and tedious to have to use that function all the time. So what I am hoping for is that PHP recognizes there are two strategies = for error handling =E2=80=94 1. Throwing exceptions vs. 2. Returning = error values =E2=80=94 and that PHP 8.0 and behind will respect = programmers and allow them to embrace the strategy they feel is best for = their use-case. -Mike= --Apple-Mail=_0319EF5A-29F5-4803-8929-87CD551E58BA--