Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:127770 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 lists.php.net (Postfix) with ESMTPS id 84F911A00BC for ; Fri, 27 Jun 2025 13:02:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1751029231; bh=Ruz13yJDXNgx4tTUaCqVYnhqFgq2lBzJ9HeCkw4vjxc=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=NxTQ9KOp+quodFOXpnKU9Gl9Fkil+/6QkdebSMxKkr1/WVF19pSsGtcjqNRCu3m9O 0MujI8IbM6GD5gtqrFZwtPojzhY5RgL3+KH/pnrMQJQ7VEyBxEURMnuV/JUX2BgqSh WAA4851ZYRdFnzxSQTHVQ4LaFIC4e3lWgAEOCBRBRagy7URbhhnyn+pzYJ/ywtpunk M8s9/WMBk9V1ojIrnGAECbPuvK/Lp1+/0PMeJ2R/DRTc4ihqKKqbgc9Lboij/hP9Sw pRQuFytcYRqPIe+Niq0+bx1zUc8Y9NqMUzZuO68cDP5bG1wWjkL/qnv/+MV16Ss7sY 3gyU+LwGf/VKQ== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id B115A18038B for ; Fri, 27 Jun 2025 13:00:27 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-0.4 required=5.0 tests=BAYES_50,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.1 X-Spam-Virus: Error (Cannot connect to unix socket '/var/run/clamav/clamd.ctl': connect: Connection refused) X-Envelope-From: Received: from mail-yw1-f169.google.com (mail-yw1-f169.google.com [209.85.128.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 ; Fri, 27 Jun 2025 13:00:25 +0000 (UTC) Received: by mail-yw1-f169.google.com with SMTP id 00721157ae682-70e2a7a2ce6so2172167b3.0 for ; Fri, 27 Jun 2025 06:02:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1751029340; x=1751634140; 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=6fuS0Es41GQ9FItbdt5YoM/zW4e0U8CI9jZdj449dcQ=; b=Ams1lj2N0EP30wrVNV426vbGwbEyagdKpYqtCeqG+hke2EVua+vw0jokVUYmFqP3hw SCZIFZUm96ofjmK7rmEjQOz5E+9wObe1Gdhs04nWEiTjKTwCHLjVMWcFiKOIWTrX9tHb z9C09UYlm5vTlTxtvHpP/rXk/c2xd32+WZ9Q4+2sqq+wW0eIK7OWP5TVeNA+0bBX21z6 nWMwTHUPL/edPxO2edvzFKYmEHRBBuGoyIdI0d9G6uOndqPClSRzmuz0iuFUtatsfCCy IBwil3IDMUq9rbpX/duDj5T0HfkHwk9nonleu1svx7S+vaFNWidXNzrTuYLhlphZ+bW/ rhpg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751029340; x=1751634140; 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=6fuS0Es41GQ9FItbdt5YoM/zW4e0U8CI9jZdj449dcQ=; b=d2MdLQhbwrlEoSIHPvt8mOqcWKIMabw7xWimBQs4LTT/8B7pfHcWS12JulrSm1nBt7 sh6Vejp8nCBU29YIT8hq3XxLIvdg2vVCeuHOQ94gUhDvXbmxFVnAdw0FKGZBEDeDK1PP dmVF8PSD6dDB22IOUInTOSLjtkFKsECvsNQ4UwfeI6VL4Gu5ibeW4ytR6rwB6kMSNthz 55TF62ZfAQhQgwD8H3M7g9wPcQhRZIerSbR1HTsVsCViqqP/F3Zf3/Mg2wB93si/SgQy dEkxHhx1VCJepRnGhsoLAeeUW9ICOmsbZEmWckorNxOnqWHZ9Raj9HvhKRAUrMgcFMEj RMmQ== X-Forwarded-Encrypted: i=1; AJvYcCXr6597xBCo+PNYxxqXqushPqaz0A0P5FiFmtsv3VE9dNDGS5jBp+PvC1zBrCEhKKeQ9uOcyulh50M=@lists.php.net X-Gm-Message-State: AOJu0YwYWV4teNaNG0QUoHSBVNCZTiuR+rBgRTQic7L2/QK3IHvX9Nun RKdgFH1+xZNf4vGboa+/rqLzw2scHVKXrQWVLoaShtpAHTQIvskYUU5hcTjO9YVISCExPFK4qjl a/R9JXyZEQqfzDY36HGDTsvlbDRIXvmI= X-Gm-Gg: ASbGncvAbvp6W2RHlwpmtNuEou/Nk0GpitoiuSmeidaYXGI7/B1Aj9wL43a6RL+26ky H2Xx8DGFjXLDGQNnpAw8tZatxOjQYi113pxQyADjZa5GcnfGljnB3REGt8U/RODp3evsnY8lqXn HBxXt1EKATYW1v3zKWIYkgYROp4A53pdnnZOeXf4qnVtd/9R+Azg61iaROKkFbPVXO3Hf8Ws4UZ nw= X-Google-Smtp-Source: AGHT+IGRSxoBj4fafZ8yLbTqasFYqXtr+dEAgyAHXF5J3IyPZoX4HTDf1oPfuw3BurYquswXHCazItAxkh+vCo8g59Y= X-Received: by 2002:a05:690c:4b82:b0:712:b6d9:d9e8 with SMTP id 00721157ae682-7151718e38dmr20340437b3.6.1751029339416; Fri, 27 Jun 2025 06:02:19 -0700 (PDT) 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: Fri, 27 Jun 2025 10:01:42 -0300 X-Gm-Features: Ac12FXwUgDNDJ7g1yhjANGAPEXWXGgNCkt_n_fTlMBzyhqgyWC6BDbrdMzxWyqs Message-ID: Subject: Re: [PHP-DEV] [RFC][DISCUSSION] Object-oriented curl API v2 To: Jordi Boggiano Cc: erictnorris@gmail.com, PHP internals Content-Type: multipart/alternative; boundary="000000000000c46e7806388d4980" From: deleugyn@gmail.com (Deleu) --000000000000c46e7806388d4980 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Fri, Jun 27, 2025 at 9:24=E2=80=AFAM Jordi Boggiano = wrote: > On 26.06.2025 18:25, Eric Norris wrote: > > - uses enumerations for curl options and other curl constants > > Overall I think the RFC is a good opportunity to clean up a few legacy > oddities in the curl API, but I need to throw in my 2c about enum usage > here, as someone that has actually implemented some complexish > curl-based client [1]. > > Currently the API is: > > curl_setopt($h, CURLOPT_SMTH, 3); > > Now moving this into multiple enums to me brings one major issue, that I > first have to think about which type the option has to then know on > which enum I find it. > > I understand this brings type safety on the value side if you have > multiple setOptionInt etc, but that does not seem worth the trade-off to > me. Type safety can already be done in static analyzers as they can see > which option you pass in, they know which value should be allowed. > > Then on top of that, assuming we'd put all options in one enum.. I am > still wondering what the added value is compared to simply having the > global constants (they could be namespaced if anything...). It's longer > to type, and does not provide any better autocompletion. > \Curl\Option::ConnectTimeout vs CURLOPT_CONNECT_TIMEOUT sounds ok to me > if people feel strongly pro-enum, but I do really hope it is then a > single enum + setOption() call. > > Best, > Jordi > > [1] > > https://github.com/composer/composer/blob/main/src/Composer/Util/Http/Cur= lDownloader.php > > Jordi Boggiano > @seldaek - https://seld.be > Reading this I can't help but feel like there's some cognitive bias *because* you have written a Curl class yourself. The author of a PHP Class that wraps Curl needs to know about every option and how to translate them back-and-forth, which is really the insight I take from your message. As a PHP developer making HTTP requests, I would never have guessed 270 options for Curl configurations and having them split into multiple Enums gives me smaller "boxes" that are easier to mentally parse individually. With that said, splitting enumerations by type rather than context does weaken the argument of split enums. I wouldn't be instinctively looking for "what enum do I need that is an int?" or "what enum do I need that is a string?" unless I already know the implementation details by heart. The Info and Pause enumerations seem more useful in that regard as they reduce the scope in which I need to understand, process and decide. With that said, for me this also threads into the bikeshedding area that could spiral into a failed RFC. Be it a single Enum for everything, constants, context-based enums or type-based enums, I would much rather have this RFC than not have it. PHP is one of the most important Web applications in the world and it severely lacks the ability to simplify Http. We could take inspiration from Python Requests [1] or Node Fetch [2] as a really simple and straightforward API that covers the vast majority of cases. I take the point that we don't need to go all the way and invent a RequestClient library in PHP and this RFC is threading on the small step of converting Curl procedural API into OOP, which is where Larry and Rowans recommendations about some minor helper methods go a really really long way compared to where we are today. [1] https://www.w3schools.com/PYTHON/ref_requests_post.asp [2] https://nodejs.org/en/learn/getting-started/fetch#basic-post-usage --=20 Marco Deleu --000000000000c46e7806388d4980 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


On Fri, Jun 27, 2025= at 9:24=E2=80=AFAM Jordi Boggiano <j.boggiano@seld.be> wrote:
On 26.06.2025 18:25, Eric Norris wrot= e:
> - uses enumerations for curl options and other curl constants

Overall I think the RFC is a good opportunity to clean up a few legacy
oddities in the curl API, but I need to throw in my 2c about enum usage here, as someone that has actually implemented some complexish
curl-based client [1].

Currently the API is:

=C2=A0=C2=A0=C2=A0=C2=A0 curl_setopt($h, CURLOPT_SMTH, 3);

Now moving this into multiple enums to me brings one major issue, that I first have to think about which type the option has to then know on
which enum I find it.

I understand this brings type safety on the value side if you have
multiple setOptionInt etc, but that does not seem worth the trade-off to me. Type safety can already be done in static analyzers as they can see which option you pass in, they know which value should be allowed.

Then on top of that, assuming we'd put all options in one enum.. I am <= br> still wondering what the added value is compared to simply having the
global constants (they could be namespaced if anything...). It's longer=
to type, and does not provide any better autocompletion.
\Curl\Option::ConnectTimeout vs CURLOPT_CONNECT_TIMEOUT sounds ok to me if people feel strongly pro-enum, but I do really hope it is then a
single enum + setOption() call.

Best,
Jordi

[1]
https://gith= ub.com/composer/composer/blob/main/src/Composer/Util/Http/CurlDownloader.ph= p

Jordi Boggiano
@seldaek - https://seld.be

Reading this I can'= ;t help but feel like there's some cognitive bias *because* you have wr= itten a Curl class yourself. The author of a PHP Class that wraps Curl need= s to know about every option and how to translate them back-and-forth, whic= h is really the insight I take from your message. As a PHP developer making= HTTP requests, I would never have guessed 270 options for Curl configurati= ons and having them split into multiple Enums gives me smaller "boxes&= quot; that are easier to mentally parse individually. With that said, split= ting enumerations by type rather than context does weaken the argument of s= plit enums. I wouldn't be instinctively looking for "what enum do = I need that is an int?" or "what enum do I need that is a string?= " unless I already know the implementation details by heart. The Info = and Pause enumerations seem more useful in that regard as they reduce the s= cope in which I need to understand, process and decide.=C2=A0
With that said, for me this also threads into the bikeshedding = area that could spiral into a failed RFC. Be it a single Enum for everythin= g, constants, context-based enums or type-based enums, I would much rather = have this RFC than not have it. PHP is one of the most important Web applic= ations in the world and it severely lacks the ability to simplify Http. We = could take inspiration from Python Requests [1] or Node Fetch [2] as a real= ly simple and straightforward API that covers the vast majority of cases. I= take the point that we don't need to go all the way and invent a Reque= stClient library in PHP and this RFC is threading on the small step of conv= erting Curl procedural API into OOP, which is where Larry and Rowans recomm= endations about some minor helper methods go a really really long way compa= red to where we are today.

[2]=C2=A0<= a href=3D"https://nodejs.org/en/learn/getting-started/fetch#basic-post-usag= e" target=3D"_blank">https://nodejs.org/en/learn/getting-started/fetch#basi= c-post-usage

--
=
Marco Deleu
<= /div>
--000000000000c46e7806388d4980--