Re: [PHP-DEV] Multiple property assigning without constructor

2024-12-04 Thread Vinicius Dias
> But often classes need constructors only to set properties. In such cases, > constructors become redundant. Actually, the behavior is not the same and the constructors are not redundant. Taking your example: ``` class Person { public string $firstName; public int $age; } $person = new

Re: [PHP-DEV] Multiple property assigning without constructor

2024-12-04 Thread Erick de Azevedo Lima
> > $person = new Person("Name", 43) { > firstName: "John", > age: 42 > }; Hi! You could achieve similar functionality with a simple user-land method "assign". If you put such a method on a trait, you can use it everywhere. See the example: $propVal) { $this->$prop

[PHP-DEV] Multiple property assigning without constructor

2024-12-04 Thread Taras Chornyi
Hi Internals, I would like to discuss the possibility of assigning multiple public properties at once during the class initialization. Currently, with constructor property promotion we've already achieved the ability to skip a lot of boilerplate code. With property accessors (aka hooks) we could r