Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:122410 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 88A391ADA70 for ; Sat, 17 Feb 2024 13:27:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1708176437; bh=nKIJTB2Aswn9ClekULZaNIS0w84kLE/caUDHMhzcJSg=; h=Date:To:From:Cc:Subject:In-Reply-To:References:From; b=e0q3nQjFuNyY9raWUwC9/6WU5xEePxJCPzuzNU8XoYfTzs/8jl7Lutpiw1VrvtcuB 4BziUvym9yti6+8sQAgbBj1HsTI33YSWOgpwe7oxkNRRoizSXdGcTyivBhJ1Mut5eU /LhPF+ZlY6J86kZZ0qksNZsUEpvs5Yf4vth8FFmmqZ5XXdgHRBbkVhBiyLtx6D/crJ GPluXH0q/F5b1hzBYDpRlUKSDPzuT6NhDfy/F+OzB1dBouwaCZGu7FFZd1QzjtBgYk Mnj81w+WTysESyTes9f2rGlvxKA9KsNog8E9qav5u206Tmd/2ZBky1+UDLjEC3U5tY mlHmrVaMahJsg== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id DE332180639 for ; Sat, 17 Feb 2024 05:27:16 -0800 (PST) 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.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from mail-40136.proton.ch (mail-40136.proton.ch [185.70.40.136]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Sat, 17 Feb 2024 05:27:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gpb.moe; s=protonmail; t=1708176432; x=1708435632; bh=nKIJTB2Aswn9ClekULZaNIS0w84kLE/caUDHMhzcJSg=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector; b=GXQ5ATIdAHpbJwrNTB1/4CBwVzQ62mP7krpHYJd7Mlh6Pe+FZc7vqaULftKtJUmK2 yPLCS2fn/9yOWkv++ETbTGXkluE9f0LIOYp4Q5vY7TICt0TB7Jv0fb1NNT6GG/cMDv cL70/ZsSjq28b0+TBFclOaO0gl1Ahai+5qEaqCzs4jz8DbyQfZozPDfNoup0LP6ut1 qaIrFaPsMLa2NvrcyjIiCaFvICOC3aW7LWEFx/vIn1SiCSS2xeRTtgSJiLgFmutbFa oQdZQMnCJMDz6u9J6LkhqPu1cqVClWt5hF/2MMcL6HaCYv2cQhy05yAZfTm+uG9JNa 1fjGhATpaNHew== Date: Sat, 17 Feb 2024 13:27:09 +0000 To: Kalle Sommer Nielsen Cc: Sara Golemon , PHP internals Subject: Re: [PHP-DEV] Re: [RFC] OOP API for cURL extension Message-ID: In-Reply-To: References: Feedback-ID: 96993444:user:proton Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable From: internals@gpb.moe ("Gina P. Banyard") On Saturday, 17 February 2024 at 07:41, Kalle Sommer Nielsen wrote: > Hi Sara >=20 > Den tors. 15. feb. 2024 kl. 21.08 skrev Sara Golemon pollita@php.net: >=20 > > * Better typing for setOpt() methods. > > Comment: Yep, this is a good and fair point. It's going to take a littl= e more dicing up of the current implementation, but hopefully not too rough= . > > Proposal: Keep untyped setOption() method (1/ Easier migration of exist= ing code, 2/ Some options may prove difficult to type), but add: > > * CurlHandle::setOptionBool(int $option, bool $value): CurlHandle > > * CurlHandle::setOptionInt(int $option, int $value): CurlHandle > > * CurlHandle::setOptionString(int $option, string $value): CurlHandle > > * etc... as needed, will this get weird when we get to Array since ther= e IS a setOptArray? Maybe we just don't mirror that one, or we call it setO= ptionMany(). Yeah, I like Many for the multiple option set, and Array for t= he single option of array type. > > Internally, the setopt handler will be split by type so that each typed= setting can call explicitly, and the untyped one can call all. >=20 >=20 > What about making the CURL options an enumeration? It would allow us > to typehint the setOptions() method and we can also make it backwards > compatible with the existing global constants: > `php public function setOption(CurlOption|int $option, mixed $value): sta= tic { if (is_int($option)) { $option =3D CurlOption::createFromConstant($op= tion); } // ... }` >=20 > The enumeration would then have a static method to transform the > global constant into a native type (which we can do internally). > Naming is obvious just TBD. The biggest potential issue I can see with > this approach is the many conditionally defined constants from older > CURL versions/feature flags from compile time. >=20 > From the many type variants of setOptions(), I am uncertain about > that, because with an enumeration, we would still need to have some > sort of whitelisting of what options can be passed into the method. >=20 I was also going to suggest to use enums for the options, and have them be = grouped by what value type they need. This would simplify the C implementation a lot, as most of the logic to han= dle the options and the value type would be done by the engine and ZPP. I don't think it is _that_ problematic to have enum cases be conditionally = defined as trying to use a case/constant that does not exist already throws= an Error in PHP 8 if the constant does not exist. I will note that this approach _technically_ breaks the handling of options= that require a callables, as the callable is checked to exist _when_ attem= pting to call it and not when actually passing it to curl_setopt. But this should change anyway if I merge my PR which "fixes" this. [1] Best regards, Gina P. Banyard [1] https://github.com/php/php-src/pull/13291