Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:122386 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 B28F11ADA70 for ; Thu, 15 Feb 2024 15:44:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1708011869; bh=xG8yUy5GiEj4CXCmu1ZjBh52ja5hIisY7+CNFQm2fA4=; h=References:In-Reply-To:From:Date:Subject:To:From; b=oLyJjGUlvWtdmg7CO7/zQGBjq0eakUGDyHxvhmG6QO+elcaFuifATzkdaCdsNHBRf i2xhJi4otRmcoRyokhBQoIaUmaNVsrgm0Sn5kc1YpU85qUJQPO1eS9nEN5q0mIXfvW AIIsfaF+SdZC8SI4KWeDxoZ94iwrpfqRlRVXPmqMx6RIPx7gYDATLH07MO0SGpIavz /n7hGViIJjU67TRl+tWKKf0gOj7ZMyy+MUA4tvON6p88bVAKrEmAl2fWLy1vFB6TAO 7EGuSyDnfij94QGhyhKLn1ug9b5z3Nw1jFEclH0v4bRFdChjUaebHyCxFtjBp8oxE5 iRBL86u/foY0Q== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 90F4D18033A for ; Thu, 15 Feb 2024 07:44:28 -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.7 required=5.0 tests=BAYES_05,DMARC_MISSING, HEADER_FROM_DIFFERENT_DOMAINS,HTML_MESSAGE,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_SOFTFAIL,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from mail-lf1-f53.google.com (mail-lf1-f53.google.com [209.85.167.53]) (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 ; Thu, 15 Feb 2024 07:44:28 -0800 (PST) Received: by mail-lf1-f53.google.com with SMTP id 2adb3069b0e04-511972043c3so1239397e87.1 for ; Thu, 15 Feb 2024 07:44:26 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708011865; x=1708616665; h=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=vtp20r9oTKIgIbCBpXGOfhI9gV8r/RgW1zuWPhxL0wQ=; b=CJoWdctcsyP3XzpWFPIXnWbfx2vg5xO5U0xlxa9qkCXDSNSWC3qSREn/tbGx2I+DPp 3KAknTTRAqcVQ0sjt/flndJsJaIChzjoPYiXlmHPKGF9KQlNanauRyWEpWqEg5OcBVvB dk7o+zsrzHViNyDDeFSluYtnnzYrxZzp9wpA8IeIK/RWnpyUrxoGZiuJ7kBeJQJSceZD SnMdOmU8gRnDQR0R3XEbkLCTbdOhibCb0lL7h0qvLY1IrPngwhs/2p2XSOoaHAIGURTE f6U3b1DRW0NAvveplostwZ4PUuV2zKJGyRGMe7Ifdeu0kYaGj/ZvYmAjjuoh+4p0xGuH 70pw== X-Gm-Message-State: AOJu0Yxj/f/YYTSRan/5Pv5LF86nM2d/ixI7q/eJWcJXeE0b6cMHoZIG SHhO01RmoNPzZK1pTL6JJiRGIQnA9lENmKOmjfsZLskoFLqOwdEgAtUXwtgxKaaevM0/yrmWfgA sN/8yPUELuBLAwFB3Bi5iIgHrARi1+vBCSh9ROcFEqMZ0sYeMBII= X-Google-Smtp-Source: AGHT+IHpWQTt/rU3cWwAFCHOS4Fw3dhevGQ8qIx2NDtbCTQAfcuA9YHz7waqMvzXAsthJI9alQVm+ijC5/lqmK8KNFM= X-Received: by 2002:a05:6512:118e:b0:511:87b4:d01 with SMTP id g14-20020a056512118e00b0051187b40d01mr2056842lfr.27.1708011864460; Thu, 15 Feb 2024 07:44:24 -0800 (PST) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net MIME-Version: 1.0 References: In-Reply-To: Date: Thu, 15 Feb 2024 08:44:13 -0700 Message-ID: Subject: [PHP-DEV] Re: [RFC] OOP API for cURL extension To: PHP internals Content-Type: multipart/alternative; boundary="0000000000007423c906116d8094" From: pollita@php.net (Sara Golemon) --0000000000007423c906116d8094 Content-Type: text/plain; charset="UTF-8" Summarizing replies so far. Won't be able to update the RFC immediately as my day job needs me, but some great discussions already, gang. Thanks! * Define the conditions under which exceptions will be thrown (and which exceptions) - I'll add these to the RFC, but in short: * CurlException - Never, it's an interface type to group the other exceptions. * CurlHandleException - Whenever a CurlHandle::method() fails (in lieu of returning false) * CurlMultiException - Same, but for the CurlMultiHandle class. * CurlShareException - Same, but for the CurlShareHandle class. * Naming styles, e.g getErrorNumber(): int vs errno() Comment: Agreed with your points. We don't have to stick to a hard line mapping of the function names. My initial translation did because my bugbear is with the lack of fluency and all the rest is just window dressing on that. Proposal: I'll rename all the new APIs according to a get*/set* scheme without abbreviations, e.g.: * CurlHandle::getErrorNumber(): int * CurlHandle::getError(): ?string * static CurlHandle::getErrorTextFromCode(int $code): ?string * CurlHandle::execute(): ?string // See late note about exec return values * CurlHandle::setOptionInt(int $option, int $value): CurlHandle * Better typing for setOpt() methods. Comment: Yep, this is a good and fair point. It's going to take a little more dicing up of the current implementation, but hopefully not too rough. Proposal: Keep untyped setOption() method (1/ Easier migration of existing 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 there IS a setOptArray? Maybe we just don't mirror that one, or we call it setOptionMany(). Yeah, I like Many for the multiple option set, and Array for the 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. * CurlHandle::exec() mixed typing of return values. Comment: Agreed. The `true` return value becomes meaningless in the RETURNTRANSFER==false case. Proposal: Update the RFC for CurlHandle::execute() to return ?string. * https://php.watch/articles/php-curl-security-hardening Comment: I'll read this later when I'm updating the RFC. * Prefer class constants to global constants. Comment: I'm less compelled by this. The global scope is polluted with the constants whether we add copies or not. Adding a second way to spell the constant name only adds a second way to spell the constant name. Proposal: Change my mind? * Request and Response objects, along the lines of PSR-18 Comment: I'd be in favor of that, but it's not the mountain I'm personally trying to climb today. No offense taken if you vote no because this isn't enough, but I don't have the cycles to go in that hard. Proposal: Write an RFC (and get it passed) and I can probably help you implement it? -Sara --0000000000007423c906116d8094 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Summarizing replies so far.=C2=A0 Won't be able t= o update the RFC immediately as my day job needs me, but some great discuss= ions already, gang. Thanks!

* Define the condition= s under which exceptions will be thrown (and which exceptions) - I'll a= dd these to the RFC, but in short:
=C2=A0 * CurlException - Never= , it's an interface type to group the other exceptions.
=C2= =A0 * CurlHandleException - Whenever a CurlHandle::method() fails (in lieu = of returning false)
=C2=A0 * CurlMultiException - Same, but for the Curl= MultiHandle class.
=C2=A0 * CurlShareException - Same, but for the CurlS= hareHandle class.

* Naming styles, e.g getErrorNumber(): int= =C2=A0 =C2=A0vs=C2=A0 =C2=A0errno()
=C2=A0 Comment: Agreed with your poi= nts.=C2=A0 We don't have to stick to a hard line mapping of the functio= n names.=C2=A0 My initial translation did because my bugbear is with the la= ck of fluency and all the rest is just window dressing on that.
=C2=A0 P= roposal: I'll rename all the new APIs according to a get*/set* scheme w= ithout abbreviations, e.g.:
=C2=A0 * CurlHandle::getErrorNumber()= : int
=C2=A0 * CurlHandle::getError(): ?string
=C2=A0 *= static CurlHandle::getErrorTextFromCode(int $code): ?string
=C2=A0 * Cu= rlHandle::execute(): ?string=C2=A0 // See late note about exec return value= s
=C2=A0 * CurlHandle::setOptionInt(int $option, int $value): CurlHandle=

* Better typing for setOpt() methods.
= =C2=A0 Comment: Yep, this is a good and fair point.=C2=A0 It's going to= take a little more dicing up of the current implementation, but hopefully = not too rough.
=C2=A0 Proposal: Keep untyped setOption() method (= 1/ Easier migration of existing code, 2/ Some options may prove difficult t= o type), but add:
=C2=A0 * CurlHandle::setOptionBool(int $option,= bool $value): CurlHandle
=C2=A0 * CurlHandle::setOptionInt(int $= option, int $value): CurlHandle
=C2=A0 * CurlHandle::setOptionStr= ing(int $option, string $value): CurlHandle
=C2=A0 * etc... as ne= eded, will this get weird when we get to Array since there IS a setOptArray= ?=C2=A0 Maybe we just don't mirror that one, or we call it setOptionMan= y(). Yeah, I like Many for the multiple option set,=C2=A0and Array for the = single option of array type.
=C2=A0 Internally, the setopt handle= r will be split by type so that each typed setting can call explicitly, and= the untyped one can call all.

* CurlHandle::exec() mixed typing of = return values.
=C2=A0 Comment: Agreed.=C2=A0 The `true` return va= lue becomes meaningless in the RETURNTRANSFER=3D=3Dfalse case.
= =C2=A0 Proposal: Update the RFC for CurlHandle::execute() to return ?string= .

*=C2=A0https://php.watch/artic= les/php-curl-security-hardening
=C2=A0 Comment: I'll read this l= ater when I'm updating the RFC.

* Prefer class consta= nts to global constants.
=C2=A0 Comment: I'm less compelled b= y this.=C2=A0 The global scope is polluted with the constants whether we ad= d copies or not.=C2=A0 Adding a second way to spell the constant name only = adds a second way to spell the constant name.
=C2=A0 Proposal: Ch= ange my mind?

* Request and Response objects, alon= g the lines of PSR-18
=C2=A0 Comment: I'd be in favor of that= , but it's not the mountain I'm personally trying to climb today.= =C2=A0 No offense taken if you vote no because this isn't enough, but I= don't have the cycles to go in that hard.
=C2=A0 =C2=A0Propo= sal: Write an RFC (and get it passed) and I can probably help you implement= it?

-Sara

--0000000000007423c906116d8094--