Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:126047 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 7A2721A010F for ; Sun, 24 Nov 2024 20:40:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1732480635; bh=1OuqwQEETowAB+RS24jqsRn0/AFFg7VUKRcO8prwp/4=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=N/XFCrGwXm6yN4z1HCGbUu6yULPmisCPb17lCyo+HQsjHhlJrHytiG8/D2s2o7+Ol dhVPFr4wtoVAXKq0R/806cK+/U3k010aoWlKcv+ujNrjZmLuDIfjv0RUUU7865x9I6 CuCQ3GD9da+zF1jP8B5iiHY2mDdb8GeQX5bN8CKdX/Y/qo64j1puA2JxBvtCupZJ6+ GxmiyX2yeR+vpAUmqRSQX3Po3xqB+Kux8T4oQkosENvJcmLtcQuP1a5a1oWFHO8Nuz Uli8aglD2TXhqLl0fC4+ePBe/qiEeHqcsXPA16d5YKxJeRUtZgklSWUZde0eZFmHQI 9MweFpS7OySgQ== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 328C0180577 for ; Sun, 24 Nov 2024 20:37:12 +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=0.9 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS, FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from mail-qt1-f179.google.com (mail-qt1-f179.google.com [209.85.160.179]) (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 ; Sun, 24 Nov 2024 20:37:09 +0000 (UTC) Received: by mail-qt1-f179.google.com with SMTP id d75a77b69052e-4668c8e757dso3308921cf.0 for ; Sun, 24 Nov 2024 12:40:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732480819; x=1733085619; 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=Ay2sMVxcM/kbyfHRcw+tnY7ZjpNwEJ6rq5/fa9dAwDA=; b=jT8GYIAGr6zb8CjS0uS1T9b4S885z5lpqsvPR1d+FPPPYUbI3LRWJfYqC6k+71nUF7 PCQp7mRymh8OCVdhTFVlFX9ezOi4KITyGemPJQWYvTzsBXtN5DWKvhO7LncXWGhVDnYF Hat442IwZNvfLdA0NsA0fDO/aNe+/osj9H83Z/uKj8M51jb2bQbWHQWjJpiAT88J0PhL dhtCGqqZ+p+i387n5lrRrw5PLM4fKO3eweWNcEoEVBDVYNoiddQfuRNh0AE/SB/VlKtq bwqPtgOPg+KcVvkGAM7UH1Yx9Si4CWb77D48Ydl9hatPe0IuvPxbJh7sujD+71K1u5YW soDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732480819; x=1733085619; 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=Ay2sMVxcM/kbyfHRcw+tnY7ZjpNwEJ6rq5/fa9dAwDA=; b=wJzzu5lRwcqJF3s5suWfk4HbJ1D2nmwrQW5czrVWV6htqRAqnlFxKJn6ztnTDfyszs S9cj5YdZiB9d/y7wzsFMIajsSoqFLHpsw17JJvnGG+JLQSLOmKWkQV8YmBfbMiGovSkv k3gpK3pTc4YxRcVDuklY7QKnjvGybYcRCH4dy7kjrTH2CaQS47rL4l5aEKx+2vG5iUD2 SwPGzAAqie+VzqHjXOdff9Rp+mjvSgdTH2gsul/7T+7/3Iqe9QfcFNAdYqrqWQeAwlgV dHmlNRbV2Xlu51q467461OOY/xKSo2Tbd5qXyjl/RzLhggt+DBPJj5St/+L+9Kl6+pno 40Ww== X-Gm-Message-State: AOJu0Yxbol4xSDvazzDoY4pgz66qwe3HdEP8GBgDrAtXwDtwA++Ayds3 9yddolMKbkuRMjmnBQDCLax8MaFTwmDwv6dMTVZw1ersTYc1ctipitnajJa/2cpJpOh/x9wBcuG TFtwEJvx9JG7+sRESeMe0X2pIynTp4T+P X-Gm-Gg: ASbGncu2odpan1hQFj3X9oLtEgJ/csvgpC8AiaoNIpNXLCwoHAJepwTRd3iNI/aO9qv 7DC12x8EWhJHruEn461stF9oXJ8RM7dI= X-Google-Smtp-Source: AGHT+IGRMPqzkPPa6vagyMNaq60Ykk7sSMXg7j3vTAJBy2dDGf9p3pLeg+TlElbdvVnDrowYqUAv68afzZ5/wyf79Uc= X-Received: by 2002:a05:622a:1b20:b0:463:17d2:4b7b with SMTP id d75a77b69052e-4653d63b11amr160219091cf.48.1732480818638; Sun, 24 Nov 2024 12:40:18 -0800 (PST) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 References: In-Reply-To: Date: Sun, 24 Nov 2024 21:40:07 +0100 Message-ID: Subject: Re: [PHP-DEV] [RFC] [Discussion] Add WHATWG compliant URL parsing API To: Larry Garfield Cc: php internals Content-Type: multipart/alternative; boundary="000000000000c676e40627ae9f0a" From: kocsismate90@gmail.com (=?UTF-8?B?TcOhdMOpIEtvY3Npcw==?=) --000000000000c676e40627ae9f0a Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi Larry, I do have concerns about the class design, though. Given the improvements > to the language, the accessor methods offer zero benefit at all. > Public-read properties (readonly or otherwise) would be faster and offer = no > less of a guarantee. If you want to allow someone to extend the class an= d > provide some custom logic, use aviz instead of readonly and extenders can > use hooks instead of the methods. The getters don't offer any value > anymore. > Yes, I knew you wouldn't like my traditional style with private properties + getters... :) So let me try to answer your suggestions: first of all, I believe the readonly class modifier serves its purpose, and I definitely want to keep it because it can ensure that all URI instances are immutable. That's why I cannot use property hooks, since they are incompatible with readonly. So only the possibility of using asymmetric visibility remains: however, since extenders still cannot hook them, this idea should also be rejected. Otherwise, I would consider using readonly with public read, although I believe traditional methods are better suited for overriding (easier syntax, decades of experience) than property hooks (my 2cents). > It took me a while to realize that, I think, the fromWhatWg() method is > using an in/out parameter for error handling. That is an insta-no on my > part. in/out reference parameters make sense in C, maybe C++, and > basically nowhere else. I view them as a code smell everywhere they're > used in PHP. Better alternatives include exceptions or union returns. > Yes, originally the RFC used a reference parameter to return the error during parsing. I knew it was controversial, but that's what was a consistent choice with other internal functions/methods. After your feedback, I changed this behavior to an union type return type: public static function parse(string $uri, ?string $baseUrl =3D null): static|array {} So that in case of failure, an array of Uri\WhatWgError objects are returned. This practice is not really idiomatic with PHP, so personally I'm not sure I like it, but neither did I particularly like passing a parameter by reference... > It looks like you've removed the with*() methods. Why? That means it > cannot be used as a builder mechanism, which is plenty valuable. (Though > could be an issue with query as a string vs array.) > > As I answered to Dennis, they were reclaimed in the meanwhile. The WhatWgError looks to me like it's begging to be an Enum. > It's probably not that visible at the first glance, but Uri\WhatWgError has 2 properties: an error code, and a position, so it's not feasible to make it an enum. I'd however create a separate Uri\WhatWgErrorCode enum containing all the error codes, so that the class constants could be removed from Uri\WhatWgError, but I felt it's overengineering so I decided not to do this. Regards, M=C3=A1t=C3=A9 --000000000000c676e40627ae9f0a Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi Larry,

I do have concerns about the class design, though.=C2=A0 Given the improvem= ents to the language, the accessor methods offer zero benefit at all.=C2=A0= Public-read properties (readonly or otherwise) would be faster and offer n= o less of a guarantee.=C2=A0 If you want to allow someone to extend the cla= ss and provide some custom logic, use aviz instead of readonly and extender= s can use hooks instead of the methods.=C2=A0 The getters don't offer a= ny value anymore.

Yes, I knew you would= n't like my traditional style with private properties + getters... :) S= o let me try to answer your suggestions: first of all, I believe the readon= ly class modifier serves=C2=A0its purpose, and I definitely want to keep it= because it can ensure that all URI instances are=C2=A0immutable. That'= s why I cannot use property hooks,=C2=A0since they are incompatible with re= adonly. So only the possibility of using asymmetric visibility remains: how= ever, since extenders still cannot hook them, this idea should also be reje= cted. Otherwise, I would consider using readonly with public read, although= I believe traditional methods are better suited for overriding (easier syn= tax, decades of experience) than property hooks (my 2cents).

=

It took me a while to realize that, I think, the fromWhatWg() method is usi= ng an in/out parameter for error handling.=C2=A0 That is an insta-no on my = part.=C2=A0 in/out reference parameters make sense in C, maybe C++, and bas= ically nowhere else.=C2=A0 I view them as a code smell everywhere they'= re used in PHP.=C2=A0 Better alternatives include exceptions or union retur= ns.

Yes, originally the RFC used a refe= rence parameter to return the error during parsing. I knew it was controver= sial, but that's what was a consistent choice with other internal funct= ions/methods.
After your feedback, I changed this behavior to an = union type return type:

public static function par= se(string $uri, ?string $baseUrl =3D null): static|array {}
<= br>
So that in case of failure, an array of Uri\WhatWgError objec= ts are returned. This practice is not really idiomatic with PHP, so persona= lly I'm not sure I like it, but neither did I particularly like=C2=A0pa= ssing a parameter by reference...


It looks like you've removed the with*() methods.=C2=A0 Why?=C2=A0 That= means it cannot be used as a builder mechanism, which is plenty valuable.= =C2=A0 (Though could be an issue with query as a string vs array.)


As I answered to Dennis, they were rec= laimed in the meanwhile.

The WhatWgError looks to me like it's begging to be an Enum.

It's probably not that visible at the first g= lance, but Uri\WhatWgError has 2 pro= perties: an error code, and a position, so it's not feasible to make it= an enum. I'd however create a separate=C2=A0Uri\WhatW= gErrorCode enum containing all the error codes, so that the class constants= could be removed from=C2=A0U= ri\WhatWgError, but I felt it= 's overengineering=C2=A0so I decided not to do this.
= =C2=A0
Regards,
M=C3=A1t=C3=A9
--000000000000c676e40627ae9f0a--