Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:111924 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 94058 invoked from network); 22 Sep 2020 21:28:45 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 22 Sep 2020 21:28:45 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 34AEA180538 for ; Tue, 22 Sep 2020 13:38:41 -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,HTML_MESSAGE, 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-oi1-f169.google.com (mail-oi1-f169.google.com [209.85.167.169]) (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, 22 Sep 2020 13:38:37 -0700 (PDT) Received: by mail-oi1-f169.google.com with SMTP id t76so22518514oif.7 for ; Tue, 22 Sep 2020 13:38:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=/CR+grLwN8kQqfdq+/osrVsDqh2g/OATNfEVbIe/XaY=; b=kt1RXcQukq1lfIXWhzEPdYq944tU/wzVe01/aNgVgc0o3z7wA6lLLBp6dHl6ENBfhr Bsw2BqeWc89fj6SMbH7A/4gE4CYdK9WYXmfa57MVmQe0LY/r010dCM7XbEKW1kt7RwdQ fxa+2Su1xJqj1hdpWCpKoBRHcRVcS5PUMWcTglWXlLLGdaxKM6k/EZGC/gxNDXsSnZqD 9nxMKsB6s0XQ4GJpBR9nv4q0UhRtKHjD2W4JBEtJWDJrAt4U5w+6KCykRNW2xD//Vj5m IrVaevahXmM+zycA/wBbeTO7Y1fw4ZViY8L7o2pF1Sbnd7TGO415M727aQ2miu02fxvF wtdw== 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=/CR+grLwN8kQqfdq+/osrVsDqh2g/OATNfEVbIe/XaY=; b=ba12J9TkNZkCpS6O4izFsWTJMfoPR5s5HdcXFzX30HKuombqkmx/OyKHxFpGoTWRPT PV10vP5v28/NTjmIoJqSsnA6+9aAf1zU2aofIRkU8TYCOKvH/9PpdSGAXQg9oOAJug7j 3t9r6RvJDH2YTNSWR4rqwlv1n9oHnGwTO3wC92joONaZxdTiyfs75uCoSfsKopMBoX/+ SZ1t6dfnptE3pp/ZL/nfTW8iHgYyFTJWz2FytoYSwD3Hkq/ouXTeFblFc9Mzg67qN7dF Xm3lUiMK0Y+dH7sGhYRxPig451kZWtnW5SUsHMraeq+ThyV0LeaRwtzPd60taEL+rLv9 QJCw== X-Gm-Message-State: AOAM531SmpTIm8r/IRQ4/vkB8TQP0NX/gXfQ527wZvPHMg2StTdyqeyf cA5Eag3cbTUTGFVPel9iy2+SO7Y/vpKlx4rk8oLjK5Qm7KRzyw== X-Google-Smtp-Source: ABdhPJyjyXf5xBBY4vmOjRuv6ov30a/sWAfEHKrie0gX2SXf1n5vUKi8O31uU6L5lYxdLPtc/gbFORnl1+CCgQW4nTI= X-Received: by 2002:aca:7205:: with SMTP id p5mr3890713oic.3.1600807113251; Tue, 22 Sep 2020 13:38:33 -0700 (PDT) MIME-Version: 1.0 References: <14b3e69c-f148-473e-a550-9624a22dfa3d@www.fastmail.com> In-Reply-To: <14b3e69c-f148-473e-a550-9624a22dfa3d@www.fastmail.com> Date: Tue, 22 Sep 2020 22:38:21 +0200 Message-ID: To: Larry Garfield Cc: php internals Content-Type: multipart/alternative; boundary="00000000000056df7205afecf32f" Subject: Re: [PHP-DEV] Attributes and strict types From: benjamin.morel@gmail.com (Benjamin Morel) --00000000000056df7205afecf32f Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable I'd expect it to obey the strict_types declaration of UseOfMyAttribute.php, too. I see it as being where the attribute's constructor is "called", even though the actual object instantiation happens somewhere else. =E2=80=94 Benjamin On Tue, 22 Sep 2020 at 16:11, Larry Garfield wrote= : > On Tue, Sep 22, 2020, at 7:58 AM, Nikita Popov wrote: > > Hi internals, > > > > I would like to clarify how attributes are supposed to interact with > > strict_types. Consider the following code, split up into three files to > > make it clear that each one could have their own strict_types mode: > > > > MyAttribute.php > > > #[Attribute] > > class MyAttribute { > > public function __construct(string $a) {} > > } > > > > UseOfMyAttribute.php > > > declare(strict_types=3D1); > > #[MyAttribute(42)] > > class Test {} > > > > AccessOfAttribute.php > > > var_dump((new > > ReflectionClass(Test::class'))->getAttributes()[0]->newInstance()); > > > > Currently, what happens is that this code will construct the attribute, > > converting int 42 into string "42", even though UseOfMyAttribute.php ha= s > > strict_types=3D1. > > > > My intuitive expectation here would be that we should be following the > > strict_types mode of wherever the attribute is being used (i.e. > > UseOfMyAttribute.php, not MyAttribute.php or AccessOfAttribute.php). > > Currently, we always assume strict_types=3D0. > > > > Is my expectation correct? > > > > Regards, > > Nikita > > I could see an argument for either UseOfMyAttribute.php or > AccessOfAttribute.php. I think I would also favor UseOfMyAttribute.php, > however, because if you get it wrong the place you have to change it is i= n > that file, so it should obey the setting in that file. > > --Larry Garfield > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: https://www.php.net/unsub.php > > --00000000000056df7205afecf32f--