Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:118835 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 96405 invoked from network); 17 Oct 2022 22:01:57 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 17 Oct 2022 22:01:57 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 7FAD4180211 for ; Mon, 17 Oct 2022 15:01:56 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_PASS, SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS29838 64.147.123.0/24 X-Spam-Virus: No X-Envelope-From: Received: from wout5-smtp.messagingengine.com (wout5-smtp.messagingengine.com [64.147.123.21]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Mon, 17 Oct 2022 15:01:55 -0700 (PDT) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.west.internal (Postfix) with ESMTP id 76B7F32004AE for ; Mon, 17 Oct 2022 18:01:53 -0400 (EDT) Received: from imap50 ([10.202.2.100]) by compute1.internal (MEProxy); Mon, 17 Oct 2022 18:01:53 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= garfieldtech.com; h=cc:content-transfer-encoding:content-type :date:date:from:from:in-reply-to:in-reply-to:message-id :mime-version:references:reply-to:sender:subject:subject:to:to; s=fm3; t=1666044113; x=1666130513; bh=Ktdl49GSygr15kXmUoQiGpUn7 8RoXlu05454rbzMgow=; b=e+RkKkkNbJocBhSAVWO+EExRA1PNxLFrPhdAPTv+5 blgu4+anCC01M61VnWSlaYt2LS+ydrCSnBZIJHyUWZrK+uW4+9pnCtcaOFcQwrO9 BhMzv6eeCkSAijuO499HzIE9TaBwmOxzqfXITvFZrqwLlGQGRWA/D4X5xgLY6Ceb QoZ9nF+FR4hhiYjq4B7AI1e7h26dE5Vrjbq91X91nMDladzOLWBgBNUKZEcBugsO tCIg4WDRwZKw6OhPUJLxeN3NssJ4exBjZvNTjJJSV0gg3iQ1e3tHg+gZpG19CQMq 9sY0cPIAfFN9e6VY2Ade1JbRmvQV9Zl9hQ+Lmmk6uddzQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:date:feedback-id:feedback-id:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:sender :subject:subject:to:to:x-me-proxy:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm3; t=1666044113; x=1666130513; bh=K tdl49GSygr15kXmUoQiGpUn78RoXlu05454rbzMgow=; b=M6Ot+86Nnz+GmrVHr 09Wl3Yf+0f6v8bklZhrQqvWx0aSpXInHBWc3T7j9Qo8AQYe+mWImwjcro8klwcZI rd5kZTBfcSkLdzQe474ejMgO63nJ3fTEQbBmmsZXQCBkciLpzj4KR5TdCJkyNMuH /RSRKXcCYodbAMLkcj+NhJa9b7HguSLa1Kf3KxOcnD0hvIOpMAHBNdY+zJOhlCyZ ZwV3egoe90Drqk9OjqAisw45OcZbRhd54v83NWU35OQquhR8WI5muxyvjOAVEc6W U06s14bWDIxP9JnJKL4qjVDXJwMPz/0HM4pMgeW0gGjqBIJM2XJGDqbvsRasmOsF +MxgA== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvfedrfeeltddgtdeiucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepofgfggfkjghffffhvffutgfgsehtqhertderreejnecuhfhrohhmpedfnfgr rhhrhicuifgrrhhfihgvlhgufdcuoehlrghrrhihsehgrghrfhhivghlughtvggthhdrtg homheqnecuggftrfgrthhtvghrnhepffffffejffdugfegvedviedttedvgfejffefffej leefjeetveehgefhhfdvgfelnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpe hmrghilhhfrhhomheplhgrrhhrhiesghgrrhhfihgvlhguthgvtghhrdgtohhm X-ME-Proxy: Feedback-ID: i8414410d:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id CA67F1700083; Mon, 17 Oct 2022 18:01:52 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.7.0-alpha0-1047-g9e4af4ada4-fm-20221005.001-g9e4af4ad Mime-Version: 1.0 Message-ID: <13af26f4-2925-44a7-a5b3-6e282ebc77a0@app.fastmail.com> In-Reply-To: <0d950416-372b-1ff5-21c2-0c6720d47a07@bastelstu.be> References: <22177032-fe72-c39b-63fe-fa4368a70852@bastelstu.be> <0d950416-372b-1ff5-21c2-0c6720d47a07@bastelstu.be> Date: Mon, 17 Oct 2022 17:01:32 -0500 To: "php internals" Content-Type: text/plain;charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] [VOTE] Improve unserialize() error handling From: larry@garfieldtech.com ("Larry Garfield") On Mon, Oct 17, 2022, at 12:33 PM, Tim D=C3=BCsterhus wrote: >>> Okay, now the Exception message changed. Personally I do not consider >>> this a BC break: I believe Exception messages are meant for human >>> consumption, not for programs. Otherwise fixing a typo in the message >>> would be a BC break. If the code wants to learn about the cause, it >>> should either use the '$code' or different types of Exception should= be >>> thrown to clarify the cause by entering a different catch() block. >>> >>=20 >> Yes, the specific error message should be part of the BC promise. This >> allows building test suites that can assert the message in a stable w= ay. > > I'm not talking about test suites here. I believe makes sense to verif= y=20 > the error message to ensure a specific error message is emitted to the=20 > human observer in the error log. > > I was talking about code that does something like this, which I consid= er=20 > to be inherently unsafe: > > try { =E2=80=A6 } > catch (SomeException $e) { > if ($e->getMessage() =3D=3D=3D 'Foobar') doSomething(); > else doSomethingElse(); > } > > As a library author I want to be able to provide the best possible=20 > Exception message to ease debugging for the user. This is not possible=20 > if I am locked into a bad choice forever. Just to be clear, such code is sometimes necessary. If the exception do= esn't include sufficient information as dedicated properties, parsing ou= t the string becomes the only option. I've had to do this myself. In 100% of cases, without exception (no pun intended), that's because th= e code that throws the exception is bad and wrong and should be fixed. = But such code absolutely exists in the wild, including in php-src. I re= cently needed to sscanf() and then explode the message of \ArgumentCount= Error as that was the only way I could find to get the class/method name= s out of it. I died inside a little. So yes, such code is inherently unsafe, but is sadly not as uncommon as = it should be. All that said, I agree that we have not and should not treat error messa= ge strings as part of the API guarantee. If anything, maybe that will h= elp incentivize people to stop writing bad (unparsable) exceptions. Which I think gets at the crux of the issue here, and what is often the = issue in BC discussions. PHP does not, and has never, guaranteed full BC for all code. It has tr= ied very hard to maintain BC for "well-behaved code." Well-behaved code= can generally update to a new version, even a new major, very easily wi= th minimal work. Any deprecations are alerted at least a year in advanc= e, sometimes several, and usually have easy-to-automate transitions that= tools like Rector can implement. (The discussion about deprecations be= ing "too noisy" in some tooling is another matter that has been hashed o= ut before, so I won't belabor it here.) Code that is following common b= est-practices rarely has an issue. The problem is that "well-behaved" is not well-defined. Is relying on a= n error message string well-behaved? I'd argue no, but as noted above s= ometimes there's no better option. Others may disagree. Is relying on = the exact exception class thrown well-behaved? Well... sometimes. Is r= elying on an error condition being swallowed rather than turning into an= exception well-behaved? I could argue either way here, honestly. Is c= ode relying on undefined variables silently becoming null well-behaved? = Absolutely not, and hasn't been for a decade, but it wasn't until PHP 8= .0 that the language called people out for it by default, so many projec= ts had a lot of catch up to do. (Eg, I did that catch up for TYPO3.) I don't know that we can make a clear definition of "well-behaved" that = everyone could agree on. It would be nice, but it's a very squishy topi= c. But it may be prudent, when not tied down to this specific RFC, to h= ave a broader discussion about better codifying (meaning, writing down) = what we consider a BC break and what we don't, what some heuristics are = for "well-behaved," and so on. That could help avoid, or at least short= en, a lot of discussions in the future. --Larry Garfield