Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:112019 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 95210 invoked from network); 6 Oct 2020 22:11:04 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 6 Oct 2020 22:11:04 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 1B2991804B3 for ; Tue, 6 Oct 2020 14:24:30 -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=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2, SPF_HELO_NONE,SPF_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com [209.85.128.45]) (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 ; Tue, 6 Oct 2020 14:24:28 -0700 (PDT) Received: by mail-wm1-f45.google.com with SMTP id k18so264111wmj.5 for ; Tue, 06 Oct 2020 14:24:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=beberlei-de.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=DjXQ5FZPZrUQbJwAIzvgn3FR9Pk7Fh9M6N3AiLFR+2Y=; b=C0LmV1aJiZF1GIAxkuWkiW1+CTIG4z0P0cIeNStphPh6mIiHngqFvvxBCF14fXMvXq mFlGsW5DSPQqbBSkLVFEeE2dDgBMafy20sllqQpv0xtLWhRzkoGpTzWyqDQomWUpORHY /yyiqv+4J2BvP7nRrFzi1lOXDW595oa3x+nFXfAvtuDlr/nbK0IolSB1u8RlycH5GX/E QDM2tdGRI6/bMuiDHQi7q5PCvdyhoChJz5/grQAh2haK9iQHqUcgUT1KvDVnVpLTRikQ rNHND9gSw9ce57wUC/7ygFPttEyRAIc0wo2DtNUrPKsQ7LslIBc7tAHmhHbVwzHruU5S Eu5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=DjXQ5FZPZrUQbJwAIzvgn3FR9Pk7Fh9M6N3AiLFR+2Y=; b=fE4m61KznR63Ba+BRQ1B/YkYTbwmOmTFQ2xFycbOlf5GBtNoeTdtmYXuQ3g+VHl5WH cJEw05JKKAI+sZEugfSeKwOjMKkJ4xXFSNskuVlVyoeNGcrVdjIST8oqpGzG6acwbvj8 5VDGGQlroHvF8+RQPlIkGKvhz1KKpVdw8hvD3/jQNHe1Pw7tm5CGdBealuhrp99qzlK+ N5GvSUzdGm2BdK/zkXubh5fO2IaxQenrpkufRDkcEmFQIl7b0q3xo9GrVKTpQ/NXWld8 ZPctbYTYZ1vtMHmp+5uwFaIi9Y7V82hwuSJLRjK+u/bErECNakb+CRKPk4Pd0GXRYEKQ XgHQ== X-Gm-Message-State: AOAM530FylLXEcSDf1EYoU7SiMYEqKMIXPSDSXd4WTDpRjH2IIXs8NV8 nXkze5V1zjOW6HgxONJjhcYa/1OpvjTlrqeNtEbcDw== X-Google-Smtp-Source: ABdhPJyJ/PoQi1C9se34ZBzgJjwculOm6ELTZ0dOhp/LU/oSE4aN+F4nOre2nRTtE2jb0UAdEm+Rp+dFY9TqoxLHqxk= X-Received: by 2002:a1c:2cc4:: with SMTP id s187mr6692258wms.36.1602019467498; Tue, 06 Oct 2020 14:24:27 -0700 (PDT) MIME-Version: 1.0 References: <33f82702-6126-fa36-48d6-71487cae1b72@gmx.net> In-Reply-To: <33f82702-6126-fa36-48d6-71487cae1b72@gmx.net> Date: Tue, 6 Oct 2020 23:24:16 +0200 Message-ID: To: Andreas Leathley Cc: PHP Internals Content-Type: multipart/alternative; boundary="00000000000048b5bb05b107396d" Subject: Re: [PHP-DEV] Attributes and constructor property promotion From: kontakt@beberlei.de (Benjamin Eberlei) --00000000000048b5bb05b107396d Content-Type: text/plain; charset="UTF-8" On Tue, Oct 6, 2020 at 6:21 PM Andreas Leathley wrote: > On 06.10.20 17:15, Sara Golemon wrote: > > My opinion on constructor property promotion (CPP) is that it's something > > for small value object classes and should probably be regarded as > > code-smell on larger classes. At the same time, annotations belong with > > more complex objects and not so much with small "struct-like" classes. > > > > Given that position, I think we should err towards strictness in how > > attributes are applied to CPP declarations. That is, we should require > > them to be meaningfully applicable to both arguments and properties in > > order to be used in a CPP context. If that's a problem for the consumer, > > then they should avoid use of CPP. > > > > -Sara > > The current usage of annotations is quite often with small struct-like > classes though - I mainly use annotations (and will use attributes) for > data that needs to be validated, or entity-like classes that contain > data. Those classes are small and simple and would benefit greatly from > CPP and attributes used in combination, so it would be a pity to make > that impossible. > > From my understanding suppressing the validation errors in this > particular case would be a good solution, or are there any serious > downsides to that? > This is my argument as well. Attributes + CPP are a powerful combination. Attributes are an important use-csae for data transfer objects, to configure validation or serialization for example: class ChangeFirstNameRequest { public function __construct( #[Validate\IsPositive] public int $id; #[Validate\NotBlank] #[Json("first_name")] public string $firstName; ) {} } > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: https://www.php.net/unsub.php > > --00000000000048b5bb05b107396d--