Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:115647 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 96423 invoked from network); 6 Aug 2021 15:29:39 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 6 Aug 2021 15:29:39 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 402461804DB for ; Fri, 6 Aug 2021 08:59:11 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.2 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,NICE_REPLY_A, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-wr1-f53.google.com (mail-wr1-f53.google.com [209.85.221.53]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Fri, 6 Aug 2021 08:59:10 -0700 (PDT) Received: by mail-wr1-f53.google.com with SMTP id c16so11676105wrp.13 for ; Fri, 06 Aug 2021 08:59:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding:content-language; bh=K5fXK1U+S2lsrO63lYY2Idgd31cxm8UlFirO5rGcDmM=; b=D7rkpQvXR2E3qyYkPWvWsSW2AsyXFm8VUrpGuz1bedMgcqR4WgyB1dpxEGUVak8aC3 KsZAKgPZvC54+tAXGwymsfOJtP9s58eiidYYj0WQJC+F70eB2e/3ot+ySdKEqnesx3wk eJejgsBEZqPL52PMYKQ//bCfOr4ZYzkUD4CvdgKQe4USSUIXiVhTZggZxslYBCyw+OY1 a8n4xwmg3yJTT+LVWn3yU/Lu9VcCG0NwTFus8nT5SFrqK1X2JMhePHxyLfw0O5WbF0MQ jnYCBxSNAV979rWihejP8HoZgRZ/64fxHzK2QuyANa0VsbCYP8rZJK/FIAi9GrANQnRW Kbww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=K5fXK1U+S2lsrO63lYY2Idgd31cxm8UlFirO5rGcDmM=; b=EKZb96qnTf1mkxva8a9FmOq3+hHVnEwm4D9KjC3MJBMMvgLzaJHjmtLaidKrZF1MhX QcYH3o4LsOmoJh8sFlXA86Nc7B588uATwx/8tSa8heN7RnHQYInxGWHR5IMGEZFCXZ3Y OQsvfaveLNRGjnr2kIP7eHkdNYJcpZFIp8h4x8Ujxm1IAgWuhH8yq5XMF/yZ5o8Ga6t4 z+OUn7DO7igs8lgDBGwH2FO4rQbX84l3/hc/3RYeshTF75KJCslFTuQ0w5l9M2oh3WuN NGCGiU9kMC8mHbDe27w/DovVB5XyXjqvhoICup3p7fmjszPhE6Y1wuNkxw4YruchQTyV RkUg== X-Gm-Message-State: AOAM532WlpcugvS/IXaMgCSkSKa7KnHsKvvBH9aQBQkeGQchynL8s986 DOs2t8t/TEw3C91qhsKCurVrIusRQDo= X-Google-Smtp-Source: ABdhPJxQE4Jeq3F1o2trt6+4qL/a0leRnASRUzUSlRC0De6HOKcaB8IbPZAFmHDnxOLP0TxaQTafDA== X-Received: by 2002:adf:e7cb:: with SMTP id e11mr11843415wrn.288.1628265547994; Fri, 06 Aug 2021 08:59:07 -0700 (PDT) Received: from [192.168.0.22] (cpc104104-brig22-2-0-cust548.3-3.cable.virginm.net. [82.10.58.37]) by smtp.googlemail.com with ESMTPSA id n7sm8893197wmd.3.2021.08.06.08.59.06 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 06 Aug 2021 08:59:07 -0700 (PDT) To: internals@lists.php.net References: <7DA18959-3463-4AAE-ABE3-B9330FEE83D2@gmail.com> Message-ID: Date: Fri, 6 Aug 2021 16:59:05 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.12.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-GB Subject: Re: [PHP-DEV] Re: [RFC] Add parse_query_string as an alternative to parse_str From: rowan.collins@gmail.com (Rowan Tommins) On 06/08/2021 16:06, Larry Garfield wrote: > Give me a properly defined HttpQuery object with named, type-enforced properties and meaningful methods. Give it a parse(string) static method and a __toString() method to convert back to a query string. Anything less is, frankly, not worth the effort. While I understand your general principle, I'm not sure what such an object would look like. There is no "standard list" of query string keys which could be named as properties on a built-in HttpQuery object; every request is different, so the user would have to provide the object to be "hydrated" in some form. Maybe it would have to be a trait, so you could write something like this? class GetUserQueryParams {     use HttpQueryParser;     private ?int $id;     private ?string $name; } $params = GetUserQueryParam::fromQueryString('?id=42'); Or a utility method that took a class name, and converted the query string parameters to named constructor arguments? class GetUserQueryParams {     public function __construct(        private ?int $id,        private ?string $name    ) {} } $params = parse_query_string('?id=42', GetUserQueryParams::class); Once you've started down that route, people will want a way to alias property names (e.g. with attributes), have parallel handling for other formats like JSON ... and before you know it you have the kind of complexity which is much easier to manage as a userland library than something tied to core. On the other hand, if core provides a sane implementation of the parsing into a generic "bag of key-value pairs" (which PHP calls an "array"), that would provide a very useful building block for any userland library to build on. Regards, -- Rowan Tommins [IMSoP]