Re: Attributes and constructor property promotion

From: Date: Tue, 06 Oct 2020 16:20:31 +0000
Subject: Re: Attributes and constructor property promotion
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-112017@lists.php.net to get a copy of this message
On 06.10.20 17:15, Sara Golemon wrote:
My opinion on constructor property promotion (CPP) is that it's something for small value object classes and should probably be regarded as code-smell on larger classes. At the same time, annotations belong with more complex objects and not so much with small "struct-like" classes. Given that position, I think we should err towards strictness in how attributes are applied to CPP declarations. That is, we should require them to be meaningfully applicable to both arguments and properties in order to be used in a CPP context. If that's a problem for the consumer, then they should avoid use of CPP. -Sara
The current usage of annotations is quite often with small struct-like classes though - I mainly use annotations (and will use attributes) for data that needs to be validated, or entity-like classes that contain data. Those classes are small and simple and would benefit greatly from CPP and attributes used in combination, so it would be a pity to make that impossible. From my understanding suppressing the validation errors in this particular case would be a good solution, or are there any serious downsides to that?

« previous php.internals (#112017) next »