Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:122375 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 096E01ACEBF for ; Thu, 15 Feb 2024 03:34:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1707968083; bh=GQNGF8JHkg4ilwNtCZqdoav9Cu59L7ZJDgjkEtlgbdM=; h=Date:Subject:To:References:From:In-Reply-To:From; b=IbZE2o8w+/Ow4YX3RRL42Uok5qHnfePwRC0vgKKcbjSxTCpK9GiuzbhSf07HSxWMN 5zAWf9GCDlmhfsf+NbhRVaCtgUY2VH1RfyxuzyCSGfq5PcrkCS63qFDg9YQLGZnWxp OIxWsgV+GgALD/rzF7VosQlbY0EmT2E0mImwDxT6gmrYhvlrk7/JJFyAJwnCsp3FqF 51gZk/hb0L1lOvlAhIiw3T1CbDTPieD3TfykYiL4IKR8YMimUtz6WlxPeX9nlHMACz zipEXep/x57fVqVRkJlg7y+ySSD6n3GNPAx1Ro8XUtN3R9ywDe5I96V4TeAmiVWWRJ 7oHahWop3iZdg== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id CE379180BE4 for ; Wed, 14 Feb 2024 19:34:42 -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.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS, HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE, 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-oi1-f174.google.com (mail-oi1-f174.google.com [209.85.167.174]) (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 ; Wed, 14 Feb 2024 19:34:42 -0800 (PST) Received: by mail-oi1-f174.google.com with SMTP id 5614622812f47-3c0467b94c6so314926b6e.0 for ; Wed, 14 Feb 2024 19:34:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wikimedia.org; s=google; t=1707968080; x=1708572880; darn=lists.php.net; h=in-reply-to:from:references:to:content-language:subject:user-agent :mime-version:date:message-id:from:to:cc:subject:date:message-id :reply-to; bh=z9tdqc+nHRbB1GdwnOiPSAHz1UE7MtcY7hEmVdsZIFg=; b=E7YAR37v8C7McnFLEO7JTlpvMtkFvk+2GSuUNq6u9BHXNIvlUWJ77Vv5KhN76SFRf/ Bta4Bc4GIRo8HXzs+EQtpVbGOYEPTn9DWs2rL4rhgS3jDdwYFXN6WBj9P/zsBAlsNuEp XZEHtvq/rDS1mxu3vu3+aCrAuO1CtafnRNEps= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707968080; x=1708572880; h=in-reply-to:from:references:to:content-language:subject:user-agent :mime-version:date:message-id:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=z9tdqc+nHRbB1GdwnOiPSAHz1UE7MtcY7hEmVdsZIFg=; b=D8wzp3OZV+E1Jjn12ZAwKUFTENCbFipaSCDzCaPpc7Y3VICFE1rTQsdxvNofrJLipE zbCrJGaPdNoO1S/DVEDDstcA4P3aWzaHvEXa2cmb3i+U6197EpUxRm6qIWZKUJBRw7k9 HIzhcpgIaOmwTc/Giu2CKEvXleJZo+pWes/88UAYPIf5726AU2fC1yTgkI37Bx/jXXfZ +QMrzuZvanPZE7AybSFXnxzSDNLAqfc4q8ksVazztBCvqsU+iJsi+JrbrKt3O9tdKOCs XdBOk4TmyzIdCE3zjB6PTqyLwMSOjrEaIAohvzM5MtJHU/xcBRlNUHlgLeb5SiNtjdiA zcbw== X-Forwarded-Encrypted: i=1; AJvYcCXw6LjY0LeAlukwxY2E5uIfr+647Ni/ImwGAwJkVSYIZsrJJ3E5UAveb+8N30jCgJe/1NiveEeafp6qBQAG4pjm7xHcDjMXiQ== X-Gm-Message-State: AOJu0YxG+/IIiaG3H4rxW7gYvywRPafZxChZXEJ4gpMyI68U8Fd5sn6s qUetw1/wEahkpU8b7osLILqWSyCIrGkempaGTcEhbl/ZgCfngau36zCDXAMa/sHA9bLL4+2qUXe W X-Google-Smtp-Source: AGHT+IEPlZ06RuJZCxmy3UQRyGabVboeCLQVcuh9Rp+4YKU5klAyBYun1F4RM+7+Qmay7lrDbUwsKw== X-Received: by 2002:a05:6808:617:b0:3c0:33b5:986d with SMTP id y23-20020a056808061700b003c033b5986dmr763802oih.15.1707968080691; Wed, 14 Feb 2024 19:34:40 -0800 (PST) Received: from [10.1.1.45] (124-168-51-30.dyn.iinet.net.au. [124.168.51.30]) by smtp.gmail.com with ESMTPSA id a30-20020aa78e9e000000b006e0a4022fa2sm202514pfr.189.2024.02.14.19.34.38 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 14 Feb 2024 19:34:40 -0800 (PST) Content-Type: multipart/alternative; boundary="------------IkxUJFpfbJgO3r58eFk0MjeB" Message-ID: <94983c1c-fa40-4a6e-8c5a-d3e10ecea856@wikimedia.org> Date: Thu, 15 Feb 2024 14:34:36 +1100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [RFC] OOP API for cURL extension Content-Language: en-US To: Sara Golemon , PHP internals References: In-Reply-To: From: tstarling@wikimedia.org (Tim Starling) This is a multi-part message in MIME format. --------------IkxUJFpfbJgO3r58eFk0MjeB Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 15/2/24 05:47, Sara Golemon wrote: > Good afternoon folks, I'd like to open discussion on adding OOP APIs > to the cURL extension. > https://wiki.php.net/rfc/curl-oop > Thanks for making this. It's certainly an improvement, but it's disappointing to see such a conservative change when the extension interface is so weird and awkward. I'm sure you know what I mean. It's easy to forget how bad it is until you have to do something without a framework, or explain it to a new developer. I guess the proper fix would be to add a new extension with new names for everything, with Request and Response objects, along the lines of PSR-18. But if I can think of a few minor backwards-compatible changes which would improve things a bit. For example, getInfo() could be split out to separate read-only properties. And setOpt() could be split out to separate chainable mutator methods. That would improve type inference in surrounding code. I see CurlHandle::exec() does not have the same return value as curl_exec() in your proposal, since errors are promoted to exceptions. But it still has a union return type. I would take it one step further, and have it unconditionally return either a string or void. Having it return a string is defensible if you consider it to be returning the final value of the body buffer. Enable CURLOPT_RETURNTRANSFER by default. If CURLOPT_WRITEFUNCTION or CURLOPT_FILE is set and thus the buffer doesn't get appended to, naturally curl_exec() will return an empty string. -- Tim Starling --------------IkxUJFpfbJgO3r58eFk0MjeB Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 7bit
On 15/2/24 05:47, Sara Golemon wrote:
Good afternoon folks, I'd like to open discussion on adding OOP APIs to the cURL extension.
https://wiki.php.net/rfc/curl-oop

Thanks for making this. It's certainly an improvement, but it's disappointing to see such a conservative change when the extension interface is so weird and awkward. I'm sure you know what I mean.

It's easy to forget how bad it is until you have to do something without a framework, or explain it to a new developer.

I guess the proper fix would be to add a new extension with new names for everything, with Request and Response objects, along the lines of PSR-18. But if I can think of a few minor backwards-compatible changes which would improve things a bit. For example, getInfo() could be split out to separate read-only properties. And setOpt() could be split out to separate chainable mutator methods. That would improve type inference in surrounding code.

I see CurlHandle::exec() does not have the same return value as curl_exec() in your proposal, since errors are promoted to exceptions. But it still has a union return type. I would take it one step further, and have it unconditionally return either a string or void.

Having it return a string is defensible if you consider it to be returning the final value of the body buffer. Enable CURLOPT_RETURNTRANSFER by default. If CURLOPT_WRITEFUNCTION or CURLOPT_FILE is set and thus the buffer doesn't get appended to, naturally curl_exec() will return an empty string.

-- Tim Starling

--------------IkxUJFpfbJgO3r58eFk0MjeB--