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 <landers.rob...@gmail.com >: > > 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 >