Newsgroups: php.internals
Path: news.php.net
Xref: news.php.net php.internals:126850
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 7E2BD1A00BC
	for <internals@lists.php.net>; Wed, 19 Mar 2025 21:18:29 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail;
	t=1742418958; bh=0YialGF0FKzG01BHAhu7YIK1INzUoAzBulNBwUqKnx0=;
	h=Date:Subject:To:Cc:References:From:In-Reply-To:From;
	b=R021JQhwXQv1PBsSfKko3fVDvW73JOIyC0NUkwjbAFNokEJC0ynBrpe4hxKAT24W6
	 EcYh/aQ6FnAuUqKTFBohI3wWHlQFDFt9A9j3mwFB+FXCjZmQMSQjGF40CPHFhRhFT3
	 ACnEN1nj+OZK67iP1dGlm970Y6YORcG0h+eP0GueQdVCELVOcJj4HcuLf4I3el8kUg
	 KfPGFNXxoIHuvWb6cFnF7UETm0prZCCvsy2tZzLBbczcWnSQT93r8MOiTIWhoBzNGG
	 Grw8MM8nc1d19GaVinJtE3WTvKf8v8yLFyBmYrG3mzWZgRSsj67tRiv6Slb5Rw90TR
	 88H5rb13vuq1A==
Received: from php-smtp4.php.net (localhost [127.0.0.1])
	by php-smtp4.php.net (Postfix) with ESMTP id 28A4A1801EF
	for <internals@lists.php.net>; Wed, 19 Mar 2025 21:15:57 +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=-3.9 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: <nyamsprod@gmail.com>
Received: from mail-wr1-f44.google.com (mail-wr1-f44.google.com [209.85.221.44])
	(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 <internals@lists.php.net>; Wed, 19 Mar 2025 21:15:56 +0000 (UTC)
Received: by mail-wr1-f44.google.com with SMTP id ffacd0b85a97d-399737f4fa4so32345f8f.0
        for <internals@lists.php.net>; Wed, 19 Mar 2025 14:18:27 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20230601; t=1742419107; x=1743023907; darn=lists.php.net;
        h=in-reply-to:from:content-language:references:cc:to:subject
         :user-agent:mime-version:date:message-id:from:to:cc:subject:date
         :message-id:reply-to;
        bh=sK+Em8+6w+YCfpI1rKi1oA8qQcMpGDsz8evSsBzHVrI=;
        b=m5elbq3wHaVopTBKr2ye5oe73YQhEp9REYR7VzPZ1kVeL9Q1Zo1JBQ2U8lCs+X/2hs
         bq3IMem4DsXxMrCsj/drUKV+56DEJYSvluuF6fcO6xuohaKQH5zmy7GcG3phRfD0aAtz
         cjPSsyszN8PEAD1BE7NwFDsJ6MsTuHEoxj3XrTIW2+OL22rf99FFJ7qJHpTOGnYXxqWm
         5iIEIZf8OIbYc0cF1k9iTQIQvbSaGhBK7CnrrtCHRCPmR7UlFV7NtsPRTP6mrFaQf413
         LFUQUT5M+CZHqPNY3cPQt8UMz7Ko7NBHy21otXoUg+VFIU007G8+Hdm9FRozZeJ0vnn4
         RO1g==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20230601; t=1742419107; x=1743023907;
        h=in-reply-to:from:content-language:references:cc:to:subject
         :user-agent:mime-version:date:message-id:x-gm-message-state:from:to
         :cc:subject:date:message-id:reply-to;
        bh=sK+Em8+6w+YCfpI1rKi1oA8qQcMpGDsz8evSsBzHVrI=;
        b=TuuWxU52zGzd+Hvdua/8v+hqlb6wh789lnVSl7GyZqbTtY0CNdR5RT3A4PcElXbU9a
         JpGpzJ7HlwU5IJfo9+AeZmFwjWNqLopoRLnlZq+K2NXN40t8MJpgMC2rZbPb/H086aux
         esQaSbFBjc5Hzh9dlWQIdgzE/FqBmP5EcngBg9YRqYklyz/X6VzzXK1GFbaL3eEJ4EVu
         or610Rve5uwRv+3kfPQYMtJILNUk/6lG2lKS3xBBGHZoaQQ5DUhdnJMgkMGkpDrMQcMu
         8ebmYepb2DLTg8v/r0ABoE1vqNKgTl08Zv6b6W411odA0RVBkGytk0S9mDFrn20lF+4w
         ytSw==
X-Gm-Message-State: AOJu0Yw+LvCHe3ZgZaiCyVdXOJsvROfdN9PWDzq6EUHaZPYB6zMKM5qT
	tbEOnimikjptPhcsblAHave+H5K/x4CEyWfF3SeEUIJEPGu0Lkl2
X-Gm-Gg: ASbGnctlx+4blF/bmYEqLCOnk5jwD8kPk+WmwLyQuacpNUwNgYU2CcDy8wf4F8Jsagt
	FjpigXaP+P1uzYdyqT51KS9HX1Dx11f55HL8JT2jO1P9AiLbBUuS7V5V6jKzTsLjgvfUbF4LmAx
	IuttklxWXKJ9oecyDdVV1bJVZn78MmnROXdVmlV4adAedUc0dwEzmi0lPdVVetJJA/OUN7KSsod
	ZDwTQRYcWuZQeW9ZMwmrROOQXnSV4A5CkdxFzmWhgxa2hfvkixvz6pIPcTZnyeGmKUWZzkSL0jm
	EtT1iV6O+hJrgwsKNwqZ1O3FhI0NSBGbBrAixDnSE1VWZLG/iSh9DuB764mF4KSJkjsEzmSzZ5g
	5dcxymbKyTplCKLemHwG9epoTtUOWoJh3UQtqEGude1E6oIF0mjLI+YuJKvGuEcNHWTPfaK5DZk
	W5+98TSVao8GTNPldgMmFLKzk=
X-Google-Smtp-Source: AGHT+IGM7e+wl+MoSU5d1CXkhekm8WqjD5qKaHlGIABXLlNwHuWkDmKFZUwirV2XgvYWiyPsijnhkQ==
X-Received: by 2002:a05:6000:1869:b0:391:412b:e22b with SMTP id ffacd0b85a97d-399795acf02mr838495f8f.18.1742419106305;
        Wed, 19 Mar 2025 14:18:26 -0700 (PDT)
Received: from ?IPV6:2a02:1811:3716:cb00:4120:ef96:c467:98bd? (ptr-9c16nbcfv7f8hqptprx.18120a2.ip6.access.telenet.be. [2a02:1811:3716:cb00:4120:ef96:c467:98bd])
        by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-395c8975febsm22493979f8f.59.2025.03.19.14.18.25
        (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128);
        Wed, 19 Mar 2025 14:18:25 -0700 (PDT)
Content-Type: multipart/alternative;
 boundary="------------AnfSM5bLF7xH5RbQiVZR8VOz"
Message-ID: <2e95e8fe-7cf0-493f-bd0a-9fff0956baaa@gmail.com>
Date: Wed, 19 Mar 2025 22:18:24 +0100
Precedence: bulk
list-help: <mailto:internals+help@lists.php.net
list-unsubscribe: <mailto:internals+unsubscribe@lists.php.net>
list-post: <mailto:internals@lists.php.net>
List-Id: internals.lists.php.net
x-ms-reactions: disallow
MIME-Version: 1.0
User-Agent: Mozilla Thunderbird
Subject: Re: [PHP-DEV] [RFC] [Discussion] Add WHATWG compliant URL parsing API
To: =?UTF-8?B?TcOhdMOpIEtvY3Npcw==?= <kocsismate90@gmail.com>
Cc: PHP Internals List <internals@lists.php.net>
References: <CAH5C8xUb1O20ZDrOQNC=ckFxHUUWSK7sw_njQQzFBd0qgQqoww@mail.gmail.com>
 <dd61999c-1ebd-4765-9add-cd8065968965@gmail.com>
 <CAOV5rgYZ_s1of-igLFEK7oqqh6=3HeYv0=JvvKvvjkcp0F6Q9Q@mail.gmail.com>
 <CAH5C8xV67frqOBCvLt73RM7QO86_pu40sHP5h71_kDRbKPtA8Q@mail.gmail.com>
 <1BCB4144-231D-45EA-A914-98EE8F0F503A@automattic.com>
 <8E614C9C-BA85-45D8-9A4E-A30D69981C5D@automattic.com>
 <CAH5C8xV69pHnSKWJrVB8EQab7vPhcaXAwYezoG6z3Oj7ZkXBaQ@mail.gmail.com>
 <bc5472e39bc607e2c7accc9d2bd6f239@bastelstu.be>
 <9bf11a89-39d9-457b-b0ea-789fd07d7370@gmail.com>
 <CAH5C8xWnoytE=jm1sxr-HcSZFzmG8SrzghinmBZa-QyGqN4uUg@mail.gmail.com>
 <6430b9ed-638d-4247-9fa9-d1a9148c382b@gmail.com>
 <CAH5C8xX3tCS3B3z2YFbRudCXi=ZNHE0scrmoFO7cXxU773EfpA@mail.gmail.com>
Content-Language: fr
In-Reply-To: <CAH5C8xX3tCS3B3z2YFbRudCXi=ZNHE0scrmoFO7cXxU773EfpA@mail.gmail.com>
From: nyamsprod@gmail.com (Ignace Nyamagana Butera)

This is a multi-part message in MIME format.
--------------AnfSM5bLF7xH5RbQiVZR8VOz
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit


On 17/03/2025 20:58, Máté Kocsis wrote:
> Hi Ignace,
>
>     1) around `Uri\UninitializedUriException` If I look at the
>     behaviour of
>     `DatetimeImmutable` in the same scenario or a Userland object
>     instead of
>     throwing an exception an error is thrown
>
>     see:
>
>     - https://3v4l.org/d4VrY
>     - https://3v4l.org/Wn7En
>
>     Shouldn't the URI feature follow the same path for consistency ?
>     Instead
>     of throwing an exception it should throw an Error on uninitialized
>     issue
>     at least.
>
>
> Yes, you are right! Uri\UninitializedUriException should extend an 
> Error indeed,
> since people shouldn't try to catch it either.
>
>
>     2) around Normalization. In case of query normalization, sorting the
>     query string is not mention does it means that with the current
>     feature
>
>     `http://example.com?foo=bar&foo=rab`
>     <http://example.com?foo=bar&foo=rab>
>     is different from
>     `http://example.com?foo=rab&foo=bar`
>     <http://example.com?foo=rab&foo=bar>
>
>
> Yes, that's the case, this feature is not implemented. As far as I see 
> though, it's better
> not to change the order of query parameters, especially the order of 
> duplicated
> parameters in order not to accidentally change the intended meaning of 
> the query string.
> What's your stance here?
>
> Máté
>
>
Hi Maté,

Thanks for the clarifications, I ask for the latter because I am trying 
to create a polyfill using league/uri-interfaces so

my questions come essentially from me trying to create the correct 
polyfill to better understand the new class (specifically,

the RFC3986 Uri). You can find the ongoing work here if you want to see

https://github.com/bakame-php/aide-uri/blob/main/src/Uri.php

While implementing the polyfill I am finding easier DX wise to make the 
constructor private and use instead named constructors for 
instantiation. I would be in favor of

`Uri::parse` and `Uri::tryParse` like it is done currently with Enum and 
the `from` and `tryfrom` named constructors.

My reasoning is as follow:

  there's no right way or wrong way to instantiate an URI there are only 
contexts. While the parse method is all about parsing a string, one 
could legitimately use other named constructors like 
`Uri::fromComponents` which would take for instance the result of 
parse_url to build a new URI. This can become handy in the case of 
RFC3986 URI if you need to create an new URI not related to the http 
scheme and that do not use all the components like the email, data or 
FTP schemes.

  By allowing creating URI based on their respective components value 
you make it easier for dev to use the class. Also this means that if we 
want to have a balance API then a `toComponents` method should come hand 
in hand with the named constructor.

I would understand if that idea to add both components related methods 
is rejected, they could be implemented on userland, but the main point 
was to prove that from the VO or the developer POV in absence of a 
clearly defined instantiation process, having a traditional constructor 
fails to convey all the different way to create an URI.

--------------AnfSM5bLF7xH5RbQiVZR8VOz
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: 8bit

<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body>
    <p><br>
    </p>
    <div class="moz-cite-prefix">On 17/03/2025 20:58, Máté Kocsis wrote:<br>
    </div>
    <blockquote type="cite"
cite="mid:CAH5C8xX3tCS3B3z2YFbRudCXi=ZNHE0scrmoFO7cXxU773EfpA@mail.gmail.com">
      <meta http-equiv="content-type" content="text/html; charset=UTF-8">
      <div dir="ltr">
        <div class="gmail_quote gmail_quote_container">
          <div>Hi Ignace,</div>
          <div><br>
          </div>
          <blockquote class="gmail_quote"
style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(77,77,77);padding-left:1ex">
            1) around `Uri\UninitializedUriException` If I look at the
            behaviour of <br>
            `DatetimeImmutable` in the same scenario or a Userland
            object instead of <br>
            throwing an exception an error is thrown<br>
            <br>
            see:<br>
            <br>
            - <a href="https://3v4l.org/d4VrY" rel="noreferrer"
              target="_blank" moz-do-not-send="true"
              class="moz-txt-link-freetext">https://3v4l.org/d4VrY</a><br>
            - <a href="https://3v4l.org/Wn7En" rel="noreferrer"
              target="_blank" moz-do-not-send="true"
              class="moz-txt-link-freetext">https://3v4l.org/Wn7En</a><br>
            <br>
            Shouldn't the URI feature follow the same path for
            consistency ? Instead <br>
            of throwing an exception it should throw an Error on
            uninitialized issue<br>
            at least.<br>
          </blockquote>
          <div><br>
          </div>
          <div>Yes, you are right! <span style="color:rgb(191,191,191)">Uri\UninitializedUriException
              should extend an Error indeed,</span></div>
          <div><span style="color:rgb(191,191,191)">since people
              shouldn't try to catch it either.</span></div>
          <div> </div>
          <blockquote class="gmail_quote"
style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(77,77,77);padding-left:1ex">
            <br>
            2) around Normalization. In case of query normalization,
            sorting the <br>
            query string is not mention does it means that with the
            current feature<br>
            <br>
            `<a href="http://example.com?foo=bar&amp;foo=rab"
              rel="noreferrer" target="_blank" moz-do-not-send="true">http://example.com?foo=bar&amp;foo=rab`</a><br>
            is different from<br>
            `<a href="http://example.com?foo=rab&amp;foo=bar"
              rel="noreferrer" target="_blank" moz-do-not-send="true">http://example.com?foo=rab&amp;foo=bar`</a><br>
            <br>
          </blockquote>
          <div><br>
          </div>
          <div>Yes, that's the case, this feature is not implemented. As
            far as I see though, it's better</div>
          <div><span style="color:rgb(191,191,191)">not to change </span><span
              style="color:rgb(191,191,191)">the order of query
              parameters, especially the order of duplicated</span></div>
          <div><span style="color:rgb(191,191,191)">parameters in order
              not to accidentally change the intended meaning of the
              query string</span><span style="color:rgb(191,191,191)">.</span></div>
          <div><span style="color:rgb(191,191,191)">What's your stance
              here?</span></div>
          <div><br>
          </div>
          <div><span style="color:rgb(191,191,191)">Máté</span></div>
          <div><br>
          </div>
          <div><br>
          </div>
        </div>
      </div>
    </blockquote>
    <p>Hi Maté,</p>
    <p>Thanks for the clarifications, I ask for the latter because I am
      trying to create a polyfill using league/uri-interfaces so</p>
    <p>my questions come essentially from me trying to create the
      correct polyfill to better understand the new class (specifically,</p>
    <p>the RFC3986 Uri). You can find the ongoing work here if you want
      to see </p>
    <p><a class="moz-txt-link-freetext" href="https://github.com/bakame-php/aide-uri/blob/main/src/Uri.php">https://github.com/bakame-php/aide-uri/blob/main/src/Uri.php</a> <br>
    </p>
    <p>While implementing the polyfill I am finding easier DX wise to
      make the constructor private and use instead named constructors
      for instantiation. I would be in favor of </p>
    <p>`Uri::parse` and `Uri::tryParse` like it is done currently with
      Enum and the `from` and `tryfrom` named constructors.<br>
    </p>
    <p>My reasoning is as follow:</p>
    <p> there's no right way or wrong way to instantiate an URI there
      are only contexts. While the parse method is all about parsing a
      string, one could legitimately use other named constructors like
      `Uri::fromComponents` which would take for instance the result of
      parse_url to build a new URI. This can become handy in the case of
      RFC3986 URI if you need to create an new URI not related to the
      http scheme and that do not use all the components like the email,
      data or FTP schemes.</p>
    <p> By allowing creating URI based on their respective components
      value you make it easier for dev to use the class. Also this means
      that if we want to have a balance API then a `toComponents` method
      should come hand in hand with the named constructor.</p>
    <p>I would understand if that idea to add both components related
      methods is rejected, they could be implemented on userland, but
      the main point was to prove that from the VO or the developer POV
      in absence of a clearly defined instantiation process, having a
      traditional constructor fails to convey all the different way to
      create an URI.</p>
  </body>
</html>

--------------AnfSM5bLF7xH5RbQiVZR8VOz--