Re: RFC proposal : "new" keyword shorthand
| From: | Larry Garfield | Date: | Fri, 07 Jun 2024 19:38:57 +0000 |
| Subject: | Re: RFC proposal : "new" keyword shorthand | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-123548@lists.php.net to get a copy of this message | ||
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