Le 07/06/2024 à 21:38, Larry Garfield a écrit :
On Fri, Jun 7, 2024, at 7:20 PM, Pierre wrote:
I sincerely do not want to see a new operator for replacing the "new"
operator, because then we would have two different syntaxes which would
be semantically equivalent.
Creating a new object, in most API design, is not something you do very
often, especially when working in a framework that does it for you
(dependency injection, etc...).
This is not entirely true. Creating a new service object, yes, you rarely
never do that yourself. Creating a new data object (value object, struct
object, DTO, and a dozen other terms) is something that should happen more than
most PHP developers currently do, because most of us have primitive obsession.
(Or array obsession.)
Consider attributes: Any time you want to have an object as the value for one of the arguments to
an attribute, you need a "new." Any time you create a value object for a more strongly
typed parameter than the horrid $options array, you'll be using "new."
So I'm sympathetic to making that syntax easier, and would be OK with it if a
workable syntax was found. But so far in this thread, a workable syntax has
not been found.
I agree it's not the greatest usability concern in PHP right now, though.
--Larry Garfield
I understand your point, but why replacing "new" which is basically an
operator, with another operator ?
I do agree with you that when you use value objects, you need it a lot,
but I'd much prefer having a JS like value objects initializer syntax,
such as `Point {x: 1, y: 2}` syntax than creating another way to call
the constructor, which already has a mastered and comprehensive syntax
which is simply `new`.
As you said, it's not the greatest usability concern in PHP right now.
Pierre