I have a project that use attributes :
#[OperationQueryParam('id', IntegerOperation::class, requirements: new Numeric(min: 1, max: 2_147_483_647))]
Everything works fine but there are multiple attribute that have the same requirement argument new Numeric(min: 1, max: 2_147_483_647) so i wanted to create a static function in my numeric class :
final public static function createPostiveInt(): self {
return new self(min:1, max:2_147_483_647);
}
then call the static function instead of the direct instanciation of the Numeric object to avoid repeating the constructor parameters.
#[OperationQueryParam('id', IntegerOperation::class, requirements: Numeric::createPostiveInt())]
but i have this error : Compile Error: Constant expression contains invalid operations
Am i missing something ? Why does a direct instanciation works but not the static function ?
EDIT :
using define(POSITIVE_INT,Numeric::createPostiveInt());
works but it seems dirty.
newis a keyword. That is different.