On Fri, Jun 7, 2024 at 11:50 PM Larry Garfield <la...@garfieldtech.com> wrote:
> On Fri, Jun 7, 2024, at 9:34 PM, Erick de Azevedo Lima wrote: > > Hi all. > > > >> Em sex., 7 de jun. de 2024 às 17:53, Pierre <pierre-...@processus.org> > escreveu: > >> 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`. > > > > I also think that `new `(4 chars, if we count the blank space) is short > > enough. > > But a JS-like syntax that's already known for representing objects > > could be used. > > I'm sympathetic to something like this (changing the OP examples): > > > > class A { > > public function b() { > > echo "I'm B"; > > } > > } > > > > A::{}->b(); > > > > > > class Foo { > > public function __construct( > > public string $name > > ) {} > > } > > > > class Bar { > > public function __construct( > > public Foo $foo > > ) {} > > } > > > > $bar = Bar::{ Foo::{ "I'm foo in bar" } }; > > echo $bar->foo->name; > > > > > > #[AttributeOverrides([ > > AttributeOverride::{ > > name: "id", > > column: Column::{ name: "guest_id", type: "integer", length: > > 140 } > > }, > > AttributeOverride::{ > > name: "name", > > column: Column::{ name: "guest_name", nullable: false, unique: > > true, length: 240 } > > }] > > )] > > > > > > #[AttributeOverrides([ > > AttributeOverride::{ > > name: "id", > > column: Column::{ name: "guest_id", type: "integer", length: > > 140 } > > }, > > AttributeOverride::{ > > name: "name", > > column: Column::{ name: "guest_name", nullable: false, unique: > > true, length: 240 } > > }] > > )] > > > > -- > > Erick > > We already have named arguments, which gives nearly the same syntax. > Writing directly to properties like that makes no sense in a language that > has class-private properties and internal constructors. It's fine in Rust > or Go that don't have internal constructors, but it's just not a good fit > in a PHP-like language. > > And new Foo(a: 'A", b: 'B") is already perfectly readable and > self-documenting. Yet another constructor-invoke syntax on top of that > would offer nothing. > > --Larry Garfield > Currently there are 3 ways that I mostly see to create objects: - `new Reponse(...)`, through a public `__construct` - `Response::create(...)`, some static constructor that can be named anything - `response(...)`, where it's basically just a function making the object I personally don't really use functions for this, it's not for me. I do however often create static constructors and this means that I basically have 2 ways of creating objects. Sometimes I wish `Response::new()` would call the `__construct` variant, just so I could have all my constructors use the same syntax. I could make the default constructor private and force a second static function, but that feels like a lot of extra useless work.