Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:120257 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 40372 invoked from network); 13 May 2023 09:05:10 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 13 May 2023 09:05:10 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 6F7511804AA for ; Sat, 13 May 2023 02:05:08 -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.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,FREEMAIL_REPLY, HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-ej1-f53.google.com (mail-ej1-f53.google.com [209.85.218.53]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Sat, 13 May 2023 02:05:07 -0700 (PDT) Received: by mail-ej1-f53.google.com with SMTP id a640c23a62f3a-965ddb2093bso1583482966b.2 for ; Sat, 13 May 2023 02:05:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1683968706; x=1686560706; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :from:to:cc:subject:date:message-id:reply-to; bh=MRT8nSdYGWcCJgTZuL+LRs+v2TAgduPCaVqVgL8mt7s=; b=hm5RkC15SfKLZhZtKMBpDGke2x8ICEglzr40sMJ73OiLCkxrOecl6U8Q1I8VwOdHOK g6Wi8cP0eGZdj0+RUlIZr0M8tjauGnZpqH8ZtvdmyDV/zAox8ZhApRX6Pxx8+MOUMBh9 hfpE6hSQ4zTc4zZkH2TG9yP4yY1tMZcV+tHWuQkd41BuhOX3rTgd9NA5cRSZAoIsmuvu ztumcDk+fCH25aAZ/Uv3HCuXpRl6a0SV/i8jAccgx3s27T7IZRotFDFEIWbsyO2IbhTk /ZFKskcVNMSw23h6vpcT09g/PE2iNa94hBp4KLLE+LXEBAsM9MRvmOmLtCt94l5gRzO1 JwLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683968706; x=1686560706; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=MRT8nSdYGWcCJgTZuL+LRs+v2TAgduPCaVqVgL8mt7s=; b=kMVip2lMWdyuTBtRxp7jIfUSqs8ttVir+g2N51VR/DdekQGYbAtNTNf50BNsGQJL0V itGiXn94lWwdCJ9MoHeNfaQchOV+Rz3DgFwvMDHP6l04jreggZMTSlscdxUGJKTrW+KW 9T2M8EECFVWlKSiMaODFTG5dpt8bVchJISASmFaUYq56w/+kf6C+4wL5px2sKcDBSmpx hKmcVGK4oWtYgax+WwUwOfHxDB6mayOdsFN70VaSZHSy2eucdOyJZ66KMzEdgm6Pn/0d o541M5tvKL2GY9SXyOEiTKMCgilVu+rnMXlQI40tqa99TtLzzbP6FNZ5/tGyJA6WXlbT 7JLg== X-Gm-Message-State: AC+VfDyqm5jfi2QHjqgUmIKBcswYdI4gmr+m6mWy4dWqnWWz50ie/pcM 5p8tthMFMGMxENxvojn/tVnzUrzXpH/krgiPETeIaRtj X-Google-Smtp-Source: ACHHUZ6KHkN5jzmoj/0gOvAHXiSYBkV0hWkC3M+5kMqJYDnO8D/O6joQLpKo+svrUsFIdZzOniahSQ3XLzGs39jWUo4= X-Received: by 2002:a17:907:9405:b0:94f:5e17:e80d with SMTP id dk5-20020a170907940500b0094f5e17e80dmr25048100ejc.45.1683968705797; Sat, 13 May 2023 02:05:05 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Sat, 13 May 2023 11:04:39 +0200 Message-ID: To: internals Content-Type: multipart/alternative; boundary="00000000000085a45105fb8f84d7" Subject: Re: [PHP-DEV] [RFC] [Discussion] nameof From: flexjoly@gmail.com (Lydia de Jongh) --00000000000085a45105fb8f84d7 Content-Type: text/plain; charset="UTF-8" Wow! Yess please. My mail yesterday crossed yours, I guess (thanks Claude for answering) asking for almost the same: myClass::$normalProperty::name So I would like to add my thoughts to your proposal. I prefer a magic constant like `::name` instead of a function call as it can be used in a wider scope; for example as a parameter in an Attribute. My arguments from yesterday: > 'Directly' accessing properties and methods of the class as a parameter > in an Attribute is not really possible. > You can do that for a class with: \path\to\MyClass::class, but for > properties or methods you have to use strings, without recognition in > editors. > > It would be so nice if more items in php could be accessed with a > magic constant as you can do with ::class. > With magic constant an editor could recognize it and it limits typos > etc. and it provides the developer with a list of the properties/methods in > scope. > > Some examples from my mail yesterday for using in attributes: abstract class SaveFactoryAbstract { use ObjectBuilderTrait; #[ResetValue] protected bool $isSaved = false; #[InitObject] // tells the builder to initialize this property with the latest specs provided by (other) attributes #[ResetObject] protected ?SaveInterface $oSave = null; public function __construct(){ $this->buildMe(); // provided by the trait } } With a magic constant you could do: #[UseClass(static::$oSave::name, ImageSave::class)] // using static for normal property? #[ResetValue($this->isSaved::name, default: true)] // or using $this ?? class ImageSaveFactory extends SaveFactoryAbstract { // negative side-effect: empty classes..... } From my mail yesterday: This could also extend possibilities with/for variable variables.... Like: $this->myProp::name myClass::$staticProp::name A potential difficulty is: how to access normal properties/methods.... Maybe just as if they are static? Like parent::normalMethod() is working.... A normal property or method cannot have the same name as its static partner (sadly) so internally I hope it is not a problem. outside scope: myClass::$staticProperty::name myClass::$normalProperty::name myClass::normalMethod::name inside scope: static::$normalProperty::name self::$normalProperty::name // I do not know if 'self::' adds anything for this purpose, except for private properties/methods maybe inside class/object: $this->normalProperty::name $this->normalMethod::name $this::$staticProperty::name Greetz, Lydia P.S. I hope the spacing in de code-example is working now. Op za 13 mei 2023 om 09:27 schreef Robert Landers : > > Hello Internals, > > It is with much trepidation and excitement that I'd like to announce > the `nameof` RFC (https://wiki.php.net/rfc/nameof). It has changed > quite a bit in the last couple of days, so if you haven't seen the > latest draft, please check it out. > > Essentially, it allows using `nameof()` anywhere a string can be used, > even in static contexts. From a developer's perspective, it is a > string and from the engine's perspective, it is also mostly a string > (depending on how deep we want to go on error checking -- see the > RFC). > > If anything is unclear or if I missed something, please let me know. > > Robert Landers > Software Engineer > Utrecht NL > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: https://www.php.net/unsub.php > --00000000000085a45105fb8f84d7--