|
|
|
|
|
by sandreas
315 days ago
|
|
Well, while traits might be a workaround for certain use cases, simple arrays with scalar data types could not be extended via traits. While I know that there are Collection classes in Symfony, Laravel, etc., I'm not a huge fan of wrapping a PHP array with a class to get method chaining, even with generators. $sum = [1, 2, 3]->filter(fn($x) => $x%2!= 0)->concat([5,7])->sum();
cannot be solved with traits. Additionally, I think traits should be used very carefully and they do not have this many use cases that aren't a code smell to me. |
|