Re: RFC proposal : "new" keyword shorthand

From: Date: Fri, 07 Jun 2024 21:34:19 +0000
Subject: Re: RFC proposal : "new" keyword shorthand
References: 1 2 3 4  Groups: php.internals 
Request: Send a blank email to internals+get-123551@lists.php.net to get a copy of this message
Hi all. > Em sex., 7 de jun. de 2024 às 17:53, Pierre <pierre-php@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

« previous php.internals (#123551) next »