Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:111933 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 46144 invoked from network); 25 Sep 2020 16:09:19 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 25 Sep 2020 16:09:19 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id C1012180545 for ; Fri, 25 Sep 2020 08:19:59 -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.4 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,HTML_MESSAGE,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_SOFTFAIL autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-lf1-f52.google.com (mail-lf1-f52.google.com [209.85.167.52]) (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 ; Fri, 25 Sep 2020 08:19:59 -0700 (PDT) Received: by mail-lf1-f52.google.com with SMTP id y2so3195252lfy.10 for ; Fri, 25 Sep 2020 08:19:59 -0700 (PDT) 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=4qfFfUk/Lnwbitxp0RgMFZxYj3iPUO48GQ57D1dGXEo=; b=G9WZPGNYJHQcn8Yqj27mtTk2ko3OK0sO1nYBjvonIjmfb8HyXxtOtpeY3BzXqcFK+a h6k8P+xiVAIzNNjQ2JfHJQAZAOB0yIDiSnJMsw/KA9764OQKV7vkXvxCPdKwULE6xa0w nP0I1CZQmnB2aZ/7T5bqRPN8HHKWJ40PCBSg7mxFAuKbh8QD8r0WNEH3r0n3uC6njwNn QZ2irjahBPqTrrnCODldUiVo6NZ08MjhYow0OL8ip+Q11VZboU9MWtJVjQ5ViA0ctEz+ j7gxmCkLGixAF1aSbGqkp3Rho5y+NQyvwXalJFNhcCP2DA17Nf5yPmwCnm77d+lU/yDg TFuA== X-Gm-Message-State: AOAM532VVJdT1lwKfCpAcATcy3dH32IqeijhlCqzyvbBNLQmvp+3dz7A /uXohPy0F7piTsmB0A6Ci2MtlJV6RIylRKziEvIcXQ== X-Google-Smtp-Source: ABdhPJycgWLTkxr+Nx+HvFPQ7F3+GcRBIiqVMmd10CTT7dhtgoBUr40O+VtFR0KO3IXiD3EGj72kekngWajHG2Ov4hQ= X-Received: by 2002:ac2:46fc:: with SMTP id q28mr1655720lfo.76.1601047196924; Fri, 25 Sep 2020 08:19:56 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Fri, 25 Sep 2020 10:19:46 -0500 Message-ID: To: Nikita Popov Cc: PHP internals Content-Type: multipart/alternative; boundary="0000000000007115c105b024d99e" Subject: Re: [PHP-DEV] Attributes and strict types From: pollita@php.net (Sara Golemon) --0000000000007115c105b024d99e Content-Type: text/plain; charset="UTF-8" On Tue, Sep 22, 2020 at 7:59 AM Nikita Popov wrote: > 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? > > I would say that your expectation is correct, and I'm willing to call the current behavior a bug. No need to worry about FF here. -Sara --0000000000007115c105b024d99e--