I’ve done a lot of Googling and may have missed this, there’s so many examples of using the new Attribute feature in PHP but none of them show if this is possible. What I would like to be able to do is use the current value of the class property in the constructor arguments for the attribute. Basically something like
<?php
#[Attribute]
class MyAttr {
public function __construct ($propValue, $otherArg) { }
}
class Test {
#[MyAttr(__PROPERTY__, 'other')]
public string $prop = 'MyProp';
}
So that when using ReflectionAttribute::newInstance from within the class it effectively does new Attr('MyProp', 'other')
. Obviously __PROPERTY__
is wrong here, that just gives me the property name rather than its current value. Is it possible to get the property value in that context?