Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:126709 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by qa.php.net (Postfix) with ESMTPS id C67911A00BC for ; Tue, 11 Mar 2025 04:35:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1741667546; bh=++AGgIdmVv5LYYEG0ccGhvcqqHM6c2WAJwRYoAw1+qs=; h=Date:From:To:In-Reply-To:References:Subject:From; b=kdLr2Ws3fDwIp6xQsQIOtBrgUmMTIhs4YnmfEOzmUfAjF0heMMfC/RU0ZJe3hPGcw xJ5g4eVMbiwI+jSElZe779vNsUlZebi4aTaejv8sTWN9HMy2pXhGTn9hf2a3pr+xO8 PlqyYxyof7p4DmV4DD+LfUbP/cuo6Y8sr9ayxuDE4ScBBMAup47DgmSJfTq+IKJH7l HECf4QK5gJR9UDcFgjZBXTn4sUJ192K2izdLHj3w4tbBDp82mwjTmrZJGKfCVdyAnk 2ubGmy2ksW/7eP16cOAZnBb6GQEc7JlrbQDFJ6IowzWeH5SMB94cCsrNt4ZxOKIqpV NP3pQTQnvjB9g== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 63CBB180068 for ; Tue, 11 Mar 2025 04:32:25 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-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,DMARC_MISSING,RCVD_IN_DNSWL_LOW, SPF_HELO_PASS,SPF_NONE autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from fhigh-a7-smtp.messagingengine.com (fhigh-a7-smtp.messagingengine.com [103.168.172.158]) (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, 11 Mar 2025 04:32:24 +0000 (UTC) Received: from phl-compute-04.internal (phl-compute-04.phl.internal [10.202.2.44]) by mailfhigh.phl.internal (Postfix) with ESMTP id 1146811401B8 for ; Tue, 11 Mar 2025 00:34:58 -0400 (EDT) Received: from phl-imap-06 ([10.202.2.83]) by phl-compute-04.internal (MEProxy); Tue, 11 Mar 2025 00:34:58 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= garfieldtech.com; h=cc:content-transfer-encoding:content-type :content-type:date:date:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to; s=fm1; t=1741667698; x=1741754098; bh=9gsGDMPanFfIw6SJgbcdS OeM7C1Jkf9EfCUM23K9ZQc=; b=vuJpSZmSakI33ne3/LX7PShcw4lhS4WKNJBnj JpWrNbyJTBbmxv5rm5YASRb7JJoF0Hj0tGMOMm44sogU5xz+xfBZy5DKLAjtaP+S mXcsQZmHRbRxoTKzqcGqHrlf5vEa0erlkRnkdXLRkJb9VKSdPAUmdOsbd4O1W+pJ krRpAHdCk7eBezc8oSB/fKedT2mOunGjl/SnEv4u25NVMsOpfw7UwW1/udoHB+YU 3f9+Qj+pER4k0TF7H6UuQ/Ix23C8yuwnwzHY44wZX51mFrFjtPpAXv/ueaj7k8fv gxURpwWmZuyzaxyXgFhKt7jNXdyHZVuQsc/EN72R4e85MvD/g== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm1; t=1741667698; x=1741754098; bh=9 gsGDMPanFfIw6SJgbcdSOeM7C1Jkf9EfCUM23K9ZQc=; b=ZAkY6fBTkBPs0A9wf J7GPuSvlz2doJpDA/0msDqD2s5etkv28wqCXHOo784in4AQcNjgYX7MHqXn0OhgC hw2WIZNFj8DjcNYvbiGJGagtQaPB3yLZbyhf4g94H1xSmDABkV/yK1p7gVwBSm8L /XKylV+5ygSBel1FATNX5Bg1W44JB85QIMy5sUMpY+4AAEVI0DJDndz90CU6T+2x u8p5y2vqX3pcCBezQzv0bbpPc5vWAypa4B4FzCo8m+UQQwPg9eAzJOVIh9ewuvT7 P0zoNBUjUv7bl9Ua40FOvMAXAtd2Vkk9tYlkaGMyTpQjykWbnbZynSYhXKAy+92z LcfPg== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgdduvdduvdekucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggv pdfurfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpih gvnhhtshculddquddttddmnecujfgurhepofggfffhvffkjghfufgtgfesthhqredtredt jeenucfhrhhomhepfdfnrghrrhihucfirghrfhhivghlugdfuceolhgrrhhrhiesghgrrh hfihgvlhguthgvtghhrdgtohhmqeenucggtffrrghtthgvrhhnpedthfdtfedttddvtedt udegjeejgeetjeettefgveeffeelkeelteegveejffelgeenucffohhmrghinhepvgigth gvrhhnrghlshdrihhopdhgihhthhhusgdrtghomhenucevlhhushhtvghrufhiiigvpedt necurfgrrhgrmhepmhgrihhlfhhrohhmpehlrghrrhihsehgrghrfhhivghlughtvggthh drtghomhdpnhgspghrtghpthhtohepuddpmhhouggvpehsmhhtphhouhhtpdhrtghpthht ohepihhnthgvrhhnrghlsheslhhishhtshdrphhhphdrnhgvth X-ME-Proxy: Feedback-ID: i8414410d:Fastmail Received: by mailuser.phl.internal (Postfix, from userid 501) id CC2C029C006F; Tue, 11 Mar 2025 00:34:57 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 Date: Mon, 10 Mar 2025 23:34:37 -0500 To: "php internals" Message-ID: <8b7044d1-fde1-4701-a914-a63c8ca67099@app.fastmail.com> In-Reply-To: References: Subject: Re: [PHP-DEV] [RFC] [Discussion] Add WHATWG compliant URL parsing API Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable From: larry@garfieldtech.com ("Larry Garfield") On Mon, Mar 10, 2025, at 5:51 PM, M=C3=A1t=C3=A9 Kocsis wrote: > I'm sure that people will find their use-cases to subclass all these=20 > new classes, including the WHATWG implementation. As Nicolas mentioned, > his main use-case is minly adding convenience and new factory methods=20 > that don't specifically need all methods to be reimplemented. > > While I share your opinion that leaving the URI classes open for=20 > extension is somewhat risky and it's difficult to assess its impacts=20 > right now, I can also > sympathise with what Nicolas wrote in a later message=20 > (https://externals.io/message/123997#126489): that we shouldn't close=20 > the door for the public from > using interchangeable implementations. > > I know that going final without any interfaces is the most "convenient= "=20 > for the PHP project itself, because the solution has much less BC=20 > surface to maintain, > so we are relatively free and safe to make future changes. This is=20 > useful for an API in its early days that is huge like this. Besides th= e=20 > interests of the maintainers, > we should also take two important things into account: > > - Heterogeneous use-cases: it's out of question that the current API=20 > won't fit all use-cases, especially because we have already identified=20 > some followup tasks > that should be implemented (see "Future Scope" section in the RFC). > - Interoperability: Since URI handling is a very widespread problem,=20 > many people and libraries will start to use the new extension once it'= s=20 > available. But because > of the above reason, many of them want to use their own abstraction,=20 > and that's exactly why a common ground is needed: there's simply not a=20 > single right possible > implementation - everyone has their own, given the complexity of the=20 > topic. > > So we should try to be considerate about these factors by some way or=20 > another. So far, we have four options: > > - Making the classes open for extension: this solution has acknowledge= d=20 > technical challenges=20 > (https://github.com/php/php-src/pull/14461#discussion_r1847316607), > and it limits our possibilities of adding changes the most, but users=20 > can effectively add any behavior that they need. Of course, they are=20 > free to introduce bugs and > spec-incompatible behavior into their own implementation, but none of=20 > the other solutions could prevent such bugs either, since people will=20 > write their custom code > wherever they can: if they can't have it in a child class, then they=20 > will have in MyUri, or in UriHelper, or just in a 200 lines long=20 > function. > > Being able to extend the built-in classes also means that child classe= s=20 > can use the behavior of their parent by default - there's no need to=20 > create wrapper > classes around the built-in ones (aka using composition), that is a=20 > tedious task to implement, and also which would incur some performance=20 > penalty because of the > extra method calls. > > - Making the classes open for extension, but making some methods final= :=20 > same benefits as above, without the said technical challenges - in=20 > theory. I am currently > trying to figure out if there is a combination of methods that could b= e=20 > made final so that the known challenges become impossible to be=20 > triggered - although I haven't > managed to come up with a sensible solution yet. > > - Making the classes final: It avoids some edge-cases for the built-in=20 > classes (the uninitialized state most prominently), while it leaves th= e=20 > most room for making future > changes. Projects that may want to ship their own abstractions for the=20 > two built-in classes can use composition to create their own URI=20 > implementations. > They can instantiate these implementations however they want to (i.e.=20 > $myUri =3D new MyUri($uri)). If they need to pass an URI to other=20 > libraries then they could extract > the wrapped built-in class (i.e. $myUri->getUri()). > > On the flipside, backporting methods added in future PHP versions (aka=20 > polyfills) will become impossible to implement for URIs according to m= y=20 > knowledge, as well as mocking > in PHPUnit will also be a lost feature (I'm not sure if it's a good or=20 > a bad thing, but it may be worth to point out). > > Also, the current built-in implementations may have alternative=20 > implementations that couldn't be used instead of them. For example, th= e=20 > ADA URL library (which is mentioned > in the RFC) also implements the WHATWG specification - possibly the=20 > very same way as Lexbor, the currently used library - does. These=20 > alternative implementations may have > different performance characteristics, platform requirements, or level=20 > of maintenance/support, which may qualify them as more suitable for=20 > some use-cases than what the built-in > ones can offer. If we make these classes final, there's no way to use=20 > alternative implementations as a replacement for the default ones,=20 > although they all implement the same > specification having mostly clear semantics. > > - Making the classes final, but adding a separate interface for each:=20 > The impact of making the built-in classes final would be mitigated by=20 > adding one interface > for each specification (I didn't like this idea in the past, but it no= w=20 > looks much more useful in the perspective of the final vs non-final=20 > debate). Because of the interfaces, > there would be a common denominator for the different possible=20 > implementations. I'm sure that someone would suggest that the communit= y=20 > (aka PHP-FIG) > should come up with such an interface, but I think we shouldn't expect=20 > someone else to do the work when *we* are in the position to do it the=20 > best, as those interfaces > should be internal ones, since the built-in URI classes should also=20 > implement them. > > If we had these interfaces, projects could use whatever abstraction=20 > they want via composition, but they could more conveniently pass aroun= d=20 > the same object everywhere. > > I intentionally don't try to draw a conclusion for now, first of all=20 > because it already took me a lot of time to try to mostly objectively=20 > compare the different possibilities, and > I hope that we can find more pros-cons (or fix my reasonings if I made=20 > mistakes somewhere) in order to finally reach some kind of consensus. Thought: make the class non-final, but all of the defined methods final,= and any internal data properties private. That way we know that a chil= d class cannot break any of the existing guarantees, but can still add c= onvenience methods or static method constructors on top of the existing = API, without the need for an interface and a very verbose composing clas= s. --Larry Garfield