Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:112153 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 52963 invoked from network); 30 Oct 2020 22:34:41 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 30 Oct 2020 22:34:41 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id C466B1804B3 for ; Fri, 30 Oct 2020 14:54: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.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_PASS,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10olkn2030.outbound.protection.outlook.com [40.92.41.30]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Fri, 30 Oct 2020 14:54:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HDUucxdkqn1UOUTeXQ1woBKT6aJ2eTsE8fSXr1rELlzprDil46rt3PxUfrSmT0QO7+V2+utdQgSGV3B61rS81+gY0q0eeeFhmh+wpnhgyUnWOk2WYBh5uRU6W85BJL0Bobvex3not/E7mwatU3AKdAy6CgBfGzo3rCh/Y1IsMuHz4BcOTroA3ynZdZh3JAlzrhjnjhHXt1i08FPQEg6OEL0QscLhTaW3oYu5Zoef36XiNtx+rN1weIUgOFdqIcU8TGwQrUBAXy/lOpNDvjL5U8C3sCC8VMFxpNWKjuyBun+skgJWnh2hRoL9CVtevHsZI0ZUB/fLIg2yq4xo6N0jbA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=qCYRDH9HcwYgjndXMd9/N0u6kMuNCj5CACf4vV1BjmA=; b=ARvY6DMukcpHxySF9PBv0oXa/8jOr9ll6Iuelgdu+Li8SoYb7xW8upuhSuu7An/QCZIpVrW29B3Pkkh4ppkkTEwCJ3OG8M6kHw2rKzHbtJ30lsijtPAQKg+0gBMt07fR8nw2Z9HXzz/5oCvsZogTATAjDsq1JYyutRq1ZJd2jpEYVg6hNAB+3S656tgVQSGVqZ3j5CJfkb2WcK3NrR/qEPA20uaONergqsibT/GfEoQ1BpIbyRfZzCLLggEnZxfPhJOMCoRo2mwuOh2Qg8Tf71i5Yx0xRm+tOMfN9gqdFH1R1U2Cye1R95F+X68gq85BC5COkNF0Liv30qRIoumL+A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=qCYRDH9HcwYgjndXMd9/N0u6kMuNCj5CACf4vV1BjmA=; b=LequR5ECP8XPGObuTu0U1sEA5i1DU2P7H98qTKG8tL8iKsY2dTWwNFzZD2WKYlVOMeTWvjTPdmYqJQsSSJqoRrDyZuPHn8ZgCgtx0TxTx4fSJ0Sb9UD7fI8DyB+eeSF5deqpGmxE6BGgb2ecfXobNhDTsHRxIAN2PPxCeIovNcagPRgmjN/1aeKxyHagO2zvfoa9eZzSWXTanQX27L613qOeetsc/E/kOW2yfBkoHnpW3KNVsGSBsxUk+772kOPaC1wJn/NB8mJgamtOw2VvacJySNeNKnqzCpfOLUx+I3M2p8xbaXvdveN7Z0fmwIWXjFC3SnXM9YPL3wrIINKFPg== Received: from DM6NAM10FT060.eop-nam10.prod.protection.outlook.com (2a01:111:e400:7e86::4b) by DM6NAM10HT110.eop-nam10.prod.protection.outlook.com (2a01:111:e400:7e86::455) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3499.18; Fri, 30 Oct 2020 21:54:10 +0000 Received: from BYAPR05MB5478.namprd05.prod.outlook.com (2a01:111:e400:7e86::50) by DM6NAM10FT060.mail.protection.outlook.com (2a01:111:e400:7e86::107) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3520.17 via Frontend Transport; Fri, 30 Oct 2020 21:54:10 +0000 Received: from BYAPR05MB5478.namprd05.prod.outlook.com ([fe80::1520:24a9:8177:7990]) by BYAPR05MB5478.namprd05.prod.outlook.com ([fe80::1520:24a9:8177:7990%5]) with mapi id 15.20.3499.029; Fri, 30 Oct 2020 21:54:10 +0000 To: Rowan Tommins , PHP Internals List Thread-Topic: [PHP-DEV] List of attributes Thread-Index: AQHWlKduqAD4JLWTfUSbO6DleNAbtql92cYAgAAq64CAATgcAIAJ4ESAgBYMm8qAAZRFgIAEqHeBgAgHdACAABBagIADMPVMgAANRYCAABWhiQ== Date: Fri, 30 Oct 2020 21:54:10 +0000 Message-ID: References: ,<258d9a8e-e73e-7b8a-5d9f-64a449def1da@gmail.com> In-Reply-To: <258d9a8e-e73e-7b8a-5d9f-64a449def1da@gmail.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-incomingtopheadermarker: OriginalChecksum:241A65AB4D5A9BA7CB7FEDE2FCA4BD02AAE1DDC7DA3EBD293BBBB5BFF5325CED;UpperCasedChecksum:3656ABC69A549CDCCBA1DD08EE0EC248088AD968FF98175F7AA141A80FD591C6;SizeAsReceived:7723;Count:44 x-ms-exchange-messagesentrepresentingtype: 1 x-tmn: [5FFyNIUiklwiPw+Ua9FvhbLjpio91bWV] x-ms-publictraffictype: Email x-incomingheadercount: 44 x-eopattributedmessage: 0 x-ms-office365-filtering-correlation-id: 2c77c0cb-9f88-4bf4-55f8-08d87d1e5522 x-ms-traffictypediagnostic: DM6NAM10HT110: x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: mi+ZKhP0UTFXvnGTppNs2Sy9BAlNzNEAvj2I9ju7X+7xLbYMKr2rAJXCrbq/vqzOAv24PVIr3pJY3hPvACWCYbZo7rjQ7XwPXdTBp72arswRClw+ET9HVUqr0PflX1mys+tLfs7ib1a33OgR1LZ4dw35nHB7ewIBd35XuZsUpmGQTNPgs7egbo7rM8oRHQQ2h+Zv0ibaHmJF/DD2fYMpvA== x-ms-exchange-antispam-messagedata: w3hxImFSmoGMeIS2o1Dcrhqfgj3mMXBeXI0f7s7DrbP0o+z8WUf8IuC6Jmt4rGmPIrE0RgPMCA6zR1tt1CGHbf1vwxj16+0Y9c6ogo5XIRVB5p2lTKVmf55AhqQSb1NKt+vOB6QRfDZnZ8L20OZoLg== x-ms-exchange-transport-forked: True Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-AuthSource: DM6NAM10FT060.eop-nam10.prod.protection.outlook.com X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-Network-Message-Id: 2c77c0cb-9f88-4bf4-55f8-08d87d1e5522 X-MS-Exchange-CrossTenant-originalarrivaltime: 30 Oct 2020 21:54:10.2510 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Internet X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6NAM10HT110 Subject: Re: [PHP-DEV] List of attributes From: theodorejb@outlook.com (Theodore Brown) On Fri, Oct 30, 2020 at 2:28 PM Rowan Tommins wro= te:=0A= =0A= > On 30/10/2020 18:47, Theodore Brown wrote:=0A= > > While passing all nested attributes as an array would at least enable= =0A= > > consistent semantics, it has the notable disadvantage of preventing=0A= > > some use cases from being expressed in PHP's type system. Specifically,= =0A= > > how would you express that an attribute parameter must be passed a=0A= > > single attribute of a particular type?=0A= > =0A= > I acknowledged this use case, but suspected, and still suspect, that=0A= > it's rarer than the list-of-attributes case.=0A= > =0A= > > For example, suppose a developer wants to create/use an attribute=0A= > > like the following:=0A= > >=0A= > > #[Limit(=0A= > > min: 10,=0A= > > max: 100,=0A= > > error: #[CustomError(message: "...", notify: true, withTrace: f= alse)]=0A= > > )]=0A= > =0A= > What is the fundamental advantage of using an attribute as the argument= =0A= > here? The same thing can be expressed with an associative array:=0A= > =0A= > #[Limit(=0A= > min: 10,=0A= > max: 100,=0A= > error: ["message" =3D> "...", "notify" =3D> true, "withTrace" =3D= > false]=0A= > )]=0A= > =0A= > The only thing that seems to lose is the ability to specify the allowed= =0A= > names and types of options - but those won't be checked by the=0A= > ReflectionAttribute anyway, only once the actual constructor is run.=0A= =0A= =0A= The fundamental advantage of using an attribute here instead of an=0A= associative array is that it enables IDE autocompletion, and allows=0A= static analyzers to catch any mistakes in the parameter names/types=0A= before the code runs in production.=0A= =0A= > So there's nothing really "attribute-y" about the CustomError class,=0A= =0A= What do you mean by "attribute-y"? The `CustomError` class would be a=0A= normal attribute, and as such when calling `getArguments()` on the=0A= `Limit` ReflectionAttribute it would return a ReflectionAttribute for=0A= `CustomError`, which would allow its arguments to be inspected without=0A= loading the class.=0A= =0A= > and any "static object declaration" syntax would do, e.g.=0A= > =0A= > #[Limit(=0A= > min: 10,=0A= > max: 100,=0A= > error: CustomError{message=3D"...", notify=3Dtrue, withTrace=3Dfa= lse}=0A= > )]=0A= =0A= It's not clear what exactly you're proposing here, or how it would work.=0A= E.g. would this still allow inspecting the attribute arguments without=0A= loading the `CustomError` class? Why is a new syntax needed for this?=0A= Would it limit what the `CustomError` constructor is allowed to do? =0A= =0A= =0A= > > But if nested attributes are always passed as an array, the `$error`=0A= > > parameter would have to have an `array` type, which provides=0A= > > essentially no context about what is really required. The type system= =0A= > > would be perfectly happy to allow an empty array, or an array with=0A= > > multiple values instead of the expected single `CustomError` attribute.= =0A= > =0A= > =0A= > Again, this is a general problem, not one related to attributes: the=0A= > Symfony validation examples would be best declared as requiring=0A= > "Constraint[] $constraints" rather than "array $constraints".=0A= =0A= There is no general problem of not being able to specify that a=0A= parameter takes a single object with a particular type. This would be=0A= an artificial limitation on attributes to patch over the inherent=0A= inconsistency of the grouped syntax for nested attributes.=0A= =0A= =0A= > > 3. Vote to switch to a less verbose syntax [...]=0A= > > The downside is that...=0A= > =0A= > Let me stop you there. The downside is that a mob of Internals regulars= =0A= > will come to your house and lynch you for asking them to vote on the=0A= > same thing yet again. It just ain't gonna happen.=0A= =0A= I doubt anyone is more tired and worn out from discussing and voting=0A= on attributes than I am. But there are serious issues when it comes to=0A= supporting nested attributes with the #[] syntax and attribute grouping.=0A= Shouldn't I bring them up and propose solutions before PHP 8 is released?= =0A= =0A= Best regards, =0A= Theodore=0A=