Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:112150 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 40484 invoked from network); 30 Oct 2020 20:09:16 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 30 Oct 2020 20:09:16 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 2DDF81804B5 for ; Fri, 30 Oct 2020 12:28:45 -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.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-wr1-f54.google.com (mail-wr1-f54.google.com [209.85.221.54]) (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, 30 Oct 2020 12:28:44 -0700 (PDT) Received: by mail-wr1-f54.google.com with SMTP id n15so7696621wrq.2 for ; Fri, 30 Oct 2020 12:28:44 -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=ivRZRODQ8w60ASoYw7LNNs75EbTMrSbKBcRI8P9dZXs=; b=VZcv6oIU4cRQ78eUCvMf16Rl5DtA78K9ALTd3EvZ4W2m7dsZZDe4Hrex34UeAgvg8s 17IV81E8tXoVxFGrKqQ5XqFwOHx89ocZlpnGsbNNtUz5cW6qyMiKWEhQfOfDGin7vxQB Z627oAYQDRw815nHG1cD2wFp5B+Zkg5/mjtdv81vZdGEUIHvyGiTxVruP7pjgWW/5hL0 luMJ4RIWhA5TJKCPlRGEyJ39gfr+oXzwG3lsSa+wyxENtp06gZ25+HgbyL3Q0Ye9f7nb E0MGkV/spr3Tfp703avbPKqn0vLUX9FN8ksg3r3y/fVfXz2QBSy//0fMwGODkpc6r42F Zh6g== 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=ivRZRODQ8w60ASoYw7LNNs75EbTMrSbKBcRI8P9dZXs=; b=lOpCiavt4qNMHWcS98w8DwhQFBBFs4oVAxqGBZ2b5AviMPswO6gnJK2zFLGUWaqPOG 5YQ1ey8xdMgr0vfA2AaQYsC5Y3FVJd1m7I9Owzaf32FoIai8mroLNw4q2eg019B0ISMz rNiIaypDpu6UX4bM7US4DUH/y0gBaBjoL7Zp47+FXxXU8T5olulTy37cXRwWrZsscV/F 5yTcB3UHVSs3SmCtuI1zQgAd2UBEYmNf827h4pint3FUuOSsc5MoUmPw4514KqjM5y2r SkYY0rLAxYz9Yi9rJFQZ+evT67HWB2ILeL593iLonD50JwCLu0ykTLlhx0cxrDsQ4M3K yN+w== X-Gm-Message-State: AOAM532rt2TyFKx0Xjd4RpCBDfP1Sa1yM8VMTnNMrpz9H+Z3GX8+K2Be m2m7zmIJZoiGhRM+9aH9g+YHpKmJka8= X-Google-Smtp-Source: ABdhPJxoQqbU0051f9Lm8A188I1f7MVwYkpdxVnU8Y2/h3+zNZfOh26Lck54xqjCuNaUhl0w5afvyA== X-Received: by 2002:adf:ee44:: with SMTP id w4mr5287636wro.114.1604086121760; Fri, 30 Oct 2020 12:28:41 -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 o3sm11247190wru.15.2020.10.30.12.28.40 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 30 Oct 2020 12:28:40 -0700 (PDT) To: PHP Internals List References: Message-ID: <258d9a8e-e73e-7b8a-5d9f-64a449def1da@gmail.com> Date: Fri, 30 Oct 2020 19:28:41 +0000 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.12.1 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] List of attributes From: rowan.collins@gmail.com (Rowan Tommins) On 30/10/2020 18:47, Theodore Brown wrote: > While passing all nested attributes as an array would at least enable > consistent semantics, it has the notable disadvantage of preventing > some use cases from being expressed in PHP's type system. Specifically, > how would you express that an attribute parameter must be passed a > single attribute of a particular type? I acknowledged this use case, but suspected, and still suspect, that it's rarer than the list-of-attributes case. > For example, suppose a developer wants to create/use an attribute > like the following: > > #[Limit( > min: 10, > max: 100, > error: #[CustomError(message: "...", notify: true, withTrace: false)] > )] What is the fundamental advantage of using an attribute as the argument here? The same thing can be expressed with an associative array: #[Limit( min: 10, max: 100, error: ["message" => "...", "notify" => true, "withTrace" => false] )] The only thing that seems to lose is the ability to specify the allowed names and types of options - but those won't be checked by the ReflectionAttribute anyway, only once the actual constructor is run. So there's nothing really "attribute-y" about the CustomError class, and any "static object declaration" syntax would do, e.g. #[Limit( min: 10, max: 100, error: CustomError{message="...", notify=true, withTrace=false} )] > But if nested attributes are always passed as an array, the `$error` > parameter would have to have an `array` type, which provides > essentially no context about what is really required. The type system > would be perfectly happy to allow an empty array, or an array with > multiple values instead of the expected single `CustomError` attribute. Again, this is a general problem, not one related to attributes: the Symfony validation examples would be best declared as requiring "Constraint[] $constraints" rather than "array $constraints". > 3. Vote to switch to a less verbose syntax [...] > The downside is that... Let me stop you there. The downside is that a mob of Internals regulars will come to your house and lynch you for asking them to vote on the same thing yet again. It just ain't gonna happen. Regards, -- Rowan Tommins (né Collins) [IMSoP]