Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:122315 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 12746 invoked from network); 6 Feb 2024 20:15:39 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 6 Feb 2024 20:15:39 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1707250592; bh=G5B2vGA6bchWIBjkQQkNLgpWdy/chxnbg8S9kPv2Wao=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=oTHRIT0x4ln+v+6fF9DUhPES2Gcvqpa2LzHsrwNM+r5lMTdCXJLeiMEZIae+9g2iq LzP6GuYBcjqXxDkqLqEiZI3cSJKirI9LyhRYIbzD5uJhzFEx+W+LTeEyUSAYHhC+IQ Wc2XUSCBB2iQljJQ0/gY+wBMTN9oXdL6NSKiftndWDuG/wwwzMU47FfGGAJH4Cuiz2 ykjYQdFaZv1RV3W/lSgTMcaae4Gly/QHDcVzOQeopnqEoD/QvOpw/01KqM+tRaXjoZ 3nlxCZQ/MEdPVMJtfMuX66n6mXfhc39DFGy58UkdKtPpf3SpIMq2U/YIvOojokLy4e 5R9dDeqZANeoQ== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id D2FDF180042 for ; Tue, 6 Feb 2024 12:16:30 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,FREEMAIL_FROM, HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from mail-il1-f169.google.com (mail-il1-f169.google.com [209.85.166.169]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Tue, 6 Feb 2024 12:16:30 -0800 (PST) Received: by mail-il1-f169.google.com with SMTP id e9e14a558f8ab-363ca193a7eso3943805ab.2 for ; Tue, 06 Feb 2024 12:15:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707250537; x=1707855337; darn=lists.php.net; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=c0ZD3r9uwtXJUaCST3MEniEtpSuH5mGtKXKDdPUxREk=; b=c7bp/q/sUxkJ3oWpq+WNFt8Y9RmjLU4keR8X/q4mLDM8zSAwUIMqLx6VuMTYSSySJl SYd54rkmmGbXfJIWeycPijVJhfEQ/6gN5VYJymqh07GjvsvT6phu1SZ3eCtTR3EaXcTB X/okJlM9/jyKcJEPztYHOo+IsTz0X84wKPPm7YRVhHntVzyZrc82fd0GyXTP1iwXPoQV wT0Cvv6oNU2NKcvmlRRMGvNzskaM5HrHcw/b17JpJCuvqBs+ytbsnSmkTeDR8TlHABlG choE4FGVXuS4TeJYGxNpv1m3mpPqHBTfz4qwKruD7+xCw8LFpWVgJaGBARsB/Hu0nwZq PlvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707250537; x=1707855337; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=c0ZD3r9uwtXJUaCST3MEniEtpSuH5mGtKXKDdPUxREk=; b=puZARga6AVk4M2PDXt6Ow1XEKRt6mm30+CRpHPv5UBKyXagMkENW0Fz9l48Q696qjL aTcVqfDll5RSprdA1kqzExlKaLmkr+0hNGgvYvSwhl74rjvLneOfNwSbv2imbVf+/0+L K6pGONdLv5QVlsSmXxR3DbeF4QbGqDmcb1Jql2DdqXdSas3SlTaDA92Pj83hugRlzduP 9Gnw56mie3GcN/KWpQc1FJJa4ptF0isEKDtEJCD+S4cfrAKtY4yZ+eTBOGtFxswiYZvB ULVdII8WmRTLJmJZoBC8tBGluw7E7lPq6rxXPv7ifDeYYjEXLSfZyKGteWsO7UHNTw9O HPXQ== X-Gm-Message-State: AOJu0Ywd7TB8YBvkPKLM59ywpptRzrROzJawVG49yz589Mj/zfsxBXuu jQJUurtUI1fCQbSMP3eVPbTA4jheS0dT+aAVcwJSu1QSpK2WQUgK5gIs5n62S8+PT00CGu5LQGz foui0ncbh1oSRMAF/lqvMhHtoxyYNx8jK X-Google-Smtp-Source: AGHT+IE/TJX37BisO1ezwC4JUbM+Hi0Sraopdsu0Ha7U5p6aO3u8xoeRooCrcNR2+6NeuTcZeHif6uATNKlifM9QiXI= X-Received: by 2002:a05:6e02:1cac:b0:363:bcf2:e88f with SMTP id x12-20020a056e021cac00b00363bcf2e88fmr5069598ill.27.1707250537373; Tue, 06 Feb 2024 12:15:37 -0800 (PST) MIME-Version: 1.0 References: <742f202d-7990-4f51-b903-7a15e3fd33c2@app.fastmail.com> In-Reply-To: Date: Tue, 6 Feb 2024 22:15:00 +0200 Message-ID: To: Larry Garfield Cc: php internals Content-Type: multipart/alternative; boundary="000000000000d2a43d0610bc3deb" Subject: Re: [PHP-DEV] Feature request: https://github.com/php/php-src/issues/13301 From: arvids.godjuks@gmail.com (Arvids Godjuks) --000000000000d2a43d0610bc3deb Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Tue, 6 Feb 2024 at 22:09, Larry Garfield wrote: > On Tue, Feb 6, 2024, at 7:18 PM, Arvids Godjuks wrote: > > >> To be clear: I really like this concept and have discussed it with > others > >> before, using almost exactly this syntax. I have not proposed it > because > >> my read of Internals lately is that there's no stomach for more > >> type-centric behavior, especially with the obvious "But we already hav= e > >> exceptions, what's yer problem?" response (which is valid to a point, > but > >> also incomplete for reasons explained above). The responses in this > thread > >> so far confirm that fear, but as an optimist I'd be very happy to be > proven > >> wrong if there is an appetite for improving error handling via the typ= e > >> system. > >> > >> Absent that, union types and enums (or really any interfaced object) o= r > a > >> purpose-built Either object are the best options today, and while > they're > >> not ideal, they're not bad options either. > >> > >> None of that logic or argument requires sh*tting on OOP as a concept o= r > >> abusing others on the list, however. Doing that only undermines the > valid > >> point that there is ample headroom to improve PHP's error handling. > >> > >> --Larry Garfield > >> > >> -- > >> PHP Internals - PHP Runtime Development Mailing List > >> To unsubscribe, visit: https://www.php.net/unsub.php > >> > >> > > Thank you Larry for this interesting summary - didn't remember there wa= s > > quite a bit a discussion around the topic prior. > > > > I lean on the "we have exceptions, just leave it be" side out of > practical > > reasons - the vast majority of OO code has standardized around the > approach > > and interoperability is high. It makes using code that's out there supe= r > > easy and predictable - almost nobody uses the "return false|0|-1" out > there > > (at least I haven't used code like that except the PHP's stdlib, and ev= en > > that has been changing little by little). It makes error handling > > predictable, and considering the type of code we mostly write in PHP - > most > > of the time we leave the catching to the global top-level handler or > > sentry/bugsnag/etc libraries. > > Consistency is the word I want to highlight here. For better or for > worse - > > it's the method the PHP ecosystem arrived at and it's the predominant > one. > > Introducing a distinctly different method of error handling is going to > > bring in wrappers around libraries that convert errors to one style or > the > > other, the application code can end up using different ways of error > > handling, etc, etc. My approach is to grab a different language aka "th= e > > right tool for the job" if I want to build things differently, that's w= hy > > we have so many programming languages and not just a few :) > > > > I'd put resources into optimising the VM and php engine to handle the > > exceptions better and if there are improvements to be had there - do > those > > maybe? (I suspect JIT is also going to influence this a lot going > forward). > > > "The right tool for the job" is indeed the strongest argument for > lightweight exceptions. It's a tool we lack right now. > > I'm thinking not of "DB went away" type issues (Exceptions are already > fine there), but "requested product not found." Right now, the options w= e > have are: > > public function find($id): ?Product {} > > public function find($id): Product { > // This is very expensive I don't think will ever not be. > // It will also bubble up to the top of the application and crash the > whole process, > // Or still show up in weird, unexpected places. > throw new NotFound(); > } > > public function find($id): Product|RepoError {} > enum RepoError { > case NotFound; > } > > The first is probably most common, but null (as I go into in the article) > doesn't tell you anything and leads to mismatch errors. > > Exceptions, I'd argue, are just plain wrong in this situation. (Which > means, yes, all the frameworks that throw exceptions on route-not-found a= re > doing it wrong.) > > And the union-enum approach is a bit clunky as it has no native language > support, and no solid conventions behind it. This is my preferred approa= ch > personally today, but I think we can do better. Even just having this > available at all means that "well everyone just uses unchecked exceptions= " > isn't entirely true. (All three of the above can be found in the wild.) > > --Larry Garfield > And that, folks, is how you change people's minds. I'm on board, Larry. I agree that things like route not found, entity not found and so on don't have to be full-fat exceptions - in those cases, you indeed don't need the stack trace and other parts of it. Even the error message might not be required since whatever you "throw" or "raise" in this case is self-explanatory just by its type/object/enum type. --=20 Arv=C4=ABds Godjuks +371 26 851 664 arvids.godjuks@gmail.com Telegram: @psihius https://t.me/psihius --000000000000d2a43d0610bc3deb--