Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:111919 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 65227 invoked from network); 22 Sep 2020 15:01:14 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 22 Sep 2020 15:01:14 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 2AB4A1804E3 for ; Tue, 22 Sep 2020 07:11:05 -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.6 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, SPF_HELO_PASS,SPF_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from wout4-smtp.messagingengine.com (wout4-smtp.messagingengine.com [64.147.123.20]) (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 ; Tue, 22 Sep 2020 07:11:04 -0700 (PDT) Received: from compute7.internal (compute7.nyi.internal [10.202.2.47]) by mailout.west.internal (Postfix) with ESMTP id 26E293FE for ; Tue, 22 Sep 2020 10:11:03 -0400 (EDT) Received: from imap26 ([10.202.2.76]) by compute7.internal (MEProxy); Tue, 22 Sep 2020 10:11:03 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; bh=pY8ul/ 0fMcZjXaI9+GtNRqJOm2monCC+KfpgVV0MnMw=; b=c2e7jWSoMAK7mTbfB+Ok9t 9UQs5evg8Z4txBx960jJKeZ9itH8QkIdu1uQzFrjXBUwHFktY/68vCE5RrP1GssP DUi34xSiyzP4Z4N2JTPAqgPiTtBg82D1CEVDsoRxJeF6C6uqDHeEuwRi+HQWV05O OEsALymT/Nz8ezPWPKCiuDag5Wmbo6ZPriuo5IxRph6RYXaATVe5p+WqlCF4HuIS PTBJRpX6n3HtWjpJXErWcYcDNKc0JqmyJDOod55m9f7jPXKJu1wuGr1gxMUl61Id ORVArK+mninY0BzVBGE3afC0XbucYPtAbHIkpwdHbE44s97TisqImMELACiNcMLw == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedujedrudeggdejfecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefofgggkfgjfhffhffvufgtsehttdertderredtnecuhfhrohhmpedfnfgrrhhr hicuifgrrhhfihgvlhgufdcuoehlrghrrhihsehgrghrfhhivghlughtvggthhdrtghomh eqnecuggftrfgrthhtvghrnhepgeelgfekudeivddvteffueejffdthfejieevhefgffek udevkedtvdelvddvffefnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrg hilhhfrhhomheplhgrrhhrhiesghgrrhhfihgvlhguthgvtghhrdgtohhm X-ME-Proxy: Received: by mailuser.nyi.internal (Postfix, from userid 501) id 7A4BC1420114; Tue, 22 Sep 2020 10:11:02 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.3.0-352-gbd49b4e-fm-20200922.003-gbd49b4ec Mime-Version: 1.0 Message-ID: <14b3e69c-f148-473e-a550-9624a22dfa3d@www.fastmail.com> In-Reply-To: References: Date: Tue, 22 Sep 2020 09:10:36 -0500 To: "php internals" Content-Type: text/plain Subject: Re: [PHP-DEV] Attributes and strict types From: larry@garfieldtech.com ("Larry Garfield") 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=1); > #[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 has > strict_types=1. > > 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=0. > > 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 in that file, so it should obey the setting in that file. --Larry Garfield