Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:111917 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 56296 invoked from network); 22 Sep 2020 14:07:36 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 22 Sep 2020 14:07:36 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 771E31804E3 for ; Tue, 22 Sep 2020 06:17:26 -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,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from srv015.mail.ichtushosting.com (srv015.mail.ichtushosting.com [159.69.182.195]) (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 06:17:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=stitcher.io ; s=default; h=To:References:Message-Id:Content-Transfer-Encoding:Cc:Date: In-Reply-To:From:Subject:Mime-Version:Content-Type:Sender:Reply-To:Content-ID :Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To: Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe :List-Post:List-Owner:List-Archive; bh=iI3Boh9Foc9CRsw4ScQRleOeSDNMgBDmN8+LZ/aBJFU=; b=K3QcQs3hc/zM12+c0KgKCD8UMa eDZkBNOjX2f/WA2akTesYJOxW8m/gyY8PTWPY7Bup2D7Nzxyympr88iLeE13UeNL+33ewtBengTMC usmpDFU0UnTz/Sp7uuSVVXl8H+MBTmeEoOMY13wsGCapYRUELY2LcCRbn8KyNsC46uHb4oXHenKVU xKB8Q8zCflxuP3wpItz2nSi1gGXkNiplYwNZ5v95Jx3CWk60al+3B3CPsh8tAJWR+DneM44Z/D7Sv L0WObP8gEcOwfv3v5mkRAHsE25oTgF7jMdC70VTc3z+viwUl8zKXSZsN8E0kYAS+KUCZGnuhWkOTq ItimCFSA==; Received: from srv021.web.ichtushosting.com ([78.47.76.72]) by srv015.mail.ichtushosting.com stage1 with esmtp (Exim MailCleaner) id 1kKiAc-0000hl-Qr from ; Tue, 22 Sep 2020 15:17:22 +0200 Received: from ptr-fq9pjpg4vwo1oow4lbb.18120a2.ip6.access.telenet.be (ptr-fq9pjpg4vwo1oow4lbb.18120a2.ip6.access.telenet.be [IPv6:2a02:1812:c3c:3a00:4a6:f69d:9b06:84e7]) (Authenticated sender: brendt@stitcher.io) by srv021.web.ichtushosting.com (Postfix) with ESMTPSA id 5468420D27; Tue, 22 Sep 2020 15:17:19 +0200 (CEST) X-MailCleaner-return_path: brendt@stitcher.io X-MailCleaner-sender_address: brendt@stitcher.io X-MailCleaner-recipients: nikita.ppv@gmail.com, internals@lists.php.net Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 13.4 \(3608.80.23.2.2\)) In-Reply-To: Date: Tue, 22 Sep 2020 15:17:18 +0200 Cc: PHP internals Content-Transfer-Encoding: quoted-printable Message-ID: References: To: Nikita Popov X-Mailer: Apple Mail (2.3608.80.23.2.2) X-MailCleaner-TrustedIPs: Ok Subject: Re: [PHP-DEV] Attributes and strict types From: brendt@stitcher.io (Brent Roose) Hi Nikita =46rom a userland point of view, I'd indeed expect this example to use = strict_types, because it's declared in UseOfMyAttribute.php. Is this = something that can be changed still? Kind regards Brent > On 22 Sep 2020, at 14:58, Nikita Popov wrote: >=20 > Hi internals, >=20 > 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: >=20 > MyAttribute.php > #[Attribute] > class MyAttribute { > public function __construct(string $a) {} > } >=20 > UseOfMyAttribute.php > declare(strict_types=3D1); > #[MyAttribute(42)] > class Test {} >=20 > AccessOfAttribute.php > var_dump((new > ReflectionClass(Test::class'))->getAttributes()[0]->newInstance()); >=20 > Currently, what happens is that this code will construct the = attribute, > converting int 42 into string "42", even though UseOfMyAttribute.php = has > strict_types=3D1. >=20 > 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. >=20 > Is my expectation correct? >=20 > Regards, > Nikita