Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:123553 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by qa.php.net (Postfix) with ESMTPS id E89DC1A009C for ; Fri, 7 Jun 2024 22:44:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1717800360; bh=Vu1CgLm7zUS7zuiGp/8ovmabyJIhwrKUQLY+AAPPx8E=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=ZwzQuQqpW+WNJdHeAz8fUeEozplNLTSGfeb0Woj4OmeDRcn7CdExy24aDk3j1T2CO MLS4uqsu4dziEk+LsR1RWLG3LGv9+DjE/NjmksprV0kJ6WD1/Ysb2gLRWL0UBeEVpm gi3KodRbCdb+c10RKPDhqB7Lt1LPaVxTj1opyZ6e7XGxokWK5Vyib1sJmO9sUWBVXn WW2RCuqDGAO0Z/ex+hcS9Y/zb114pTaoeKarie+BWe5FwZucZj66C6uy2fIwJD8X0Z 7M2u1GO+zeNHNL1mZGtgtdn89FIKHHUrEiYBCpvStH0IBCiDOGqP5rfh1urYpdLqXj vgEzxaWIjQ19A== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 78005180865 for ; Fri, 7 Jun 2024 22:45:59 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=0.6 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,FREEMAIL_FROM, HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: Error (Cannot connect to unix socket '/var/run/clamav/clamd.ctl': connect: Connection refused) X-Envelope-From: Received: from mail-lj1-f171.google.com (mail-lj1-f171.google.com [209.85.208.171]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Fri, 7 Jun 2024 22:45:55 +0000 (UTC) Received: by mail-lj1-f171.google.com with SMTP id 38308e7fff4ca-2ebd421a9c7so1911951fa.3 for ; Fri, 07 Jun 2024 15:44:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1717800288; x=1718405088; darn=lists.php.net; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=wWontwyeslq5O76fgzX25y+XhkqYLzLUuZRzvGV41+4=; b=TLgzu5kmpvuwwj199+3c1XDE8Tx0px+/weGGRb9RYUdonkAMNCS12rAPiq9XPWPReJ KkOs+LSba3bTWM9u8u5kIvUt0vUhPupnxh+vvVjIjFpb+UNgn6L18phO02u3DMKUMr+Z t11X5QXPDtSkjz44kO51aobf6EhMGd9AsGGPzUbj2CKmBPoiCXNuSm4fWoX2WDg+QjmW czCnD+BRj5F7q7V5awyxTwDTZMDhrTCiENEGuMNxvcZ3JP0saGqMXS79BTGz0kRpF1ZA 1kMj/4x/AUd0hJOY36f8oB/WcsF7l3B/QwePfK25dUpcKMM8XmR2pqBcOS2RCRv3PzW3 IPoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717800288; x=1718405088; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=wWontwyeslq5O76fgzX25y+XhkqYLzLUuZRzvGV41+4=; b=UAB8LZoRLxyBkpjkssY53yKFowZnCO8AlAZKvEQvxihKX3LJgYthfzNdpojump7RGc ZAANEt98FHfegr9v6DzndbeH2xwpIAJj79X8uGqOfr3HBHLWWznTv35FC7YAnPvfyjUv 1WMVlrmsbMW78rSOptHKUZscCJVUi4fsJXwFQ7uKHRGfwnJTrgMB9ejj9D7D5/Pef1J5 ClkL0KwO+188hVQjIRdriLx6Gnh5GqSGCvYuyxcaQaApRGvyUZx3UBH52FH+7wpTREae jB1ps7vLwszfdQVReme0yhV3lozHWFk6Fpn7NqpUs+3IfUI4irwlDUSV9pWNunpZWOMa FKJQ== X-Gm-Message-State: AOJu0Yzw6HJGaUzxC0JOlL5kWuQkLhIMywzWfSFidGmt+6DwNPLNIiX7 d49LV415nk5H3RXm7vRrWe6O9UujO/nZNiBqt1t+O4kMnaBs6aAtUY7uPJI6v6STz7TJmq0qJ+w vi/Mruro1keeyfP/u7gHfs4j7azr09g== X-Google-Smtp-Source: AGHT+IE5iS3tBc2baBeMYI8MMg7iwJm9qKQVDi8Cs9Fkdku08C0U8ylojbSCjCpYQoYYeE9GlhO0yIu90c6WdkGIDKo= X-Received: by 2002:a2e:b90a:0:b0:2ea:8f55:a0fb with SMTP id 38308e7fff4ca-2eadce24b81mr23371861fa.15.1717800288129; Fri, 07 Jun 2024 15:44:48 -0700 (PDT) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net MIME-Version: 1.0 References: <652c1a66-6702-4009-a4a0-d2221df00f69@app.fastmail.com> <73390f84-4c4d-4a48-a173-24ad424e0d2e@app.fastmail.com> In-Reply-To: <73390f84-4c4d-4a48-a173-24ad424e0d2e@app.fastmail.com> Date: Sat, 8 Jun 2024 00:44:21 +0200 Message-ID: Subject: Re: [PHP-DEV] RFC proposal : "new" keyword shorthand To: Larry Garfield Cc: php internals Content-Type: multipart/alternative; boundary="000000000000f82407061a548b1e" From: kjarli@gmail.com (Lynn) --000000000000f82407061a548b1e Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Fri, Jun 7, 2024 at 11:50=E2=80=AFPM Larry Garfield wrote: > On Fri, Jun 7, 2024, at 9:34 PM, Erick de Azevedo Lima wrote: > > Hi all. > > > >> Em sex., 7 de jun. de 2024 =C3=A0s 17:53, Pierre > 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 =3D 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 tha= t > has class-private properties and internal constructors. It's fine in Rus= t > 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. --000000000000f82407061a548b1e Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


=
On Fri, Jun 7, 2024 at 11:50=E2=80=AF= PM Larry Garfield <larry@garfi= eldtech.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 =C3=A0s 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 c= all
>> the constructor, which already has a mastered and comprehensive sy= ntax
>> which is simply `new`.
>
> I also think that `new `(4 chars, if we count the blank space) is shor= t
> 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 {
>=C2=A0 =C2=A0 =C2=A0 public function b() {
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0echo "I'm B"; >=C2=A0 =C2=A0 =C2=A0 }
>=C2=A0 }
>
>=C2=A0 A::{}->b();
>
>
> class Foo {
>=C2=A0 =C2=A0 =C2=A0public function __construct(
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0public string $name
>=C2=A0 =C2=A0 =C2=A0) {}
> }
>
> class Bar {
>=C2=A0 =C2=A0 public function __construct(
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0public Foo $foo
>=C2=A0 =C2=A0 ) {}
> }
>
>=C2=A0 $bar =3D Bar::{ Foo::{ "I'm foo in bar" } };
>=C2=A0 echo $bar->foo->name;
>
>
> #[AttributeOverrides([
>=C2=A0 =C2=A0 =C2=A0AttributeOverride::{
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0name: "id",
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0column: Column::{ name: "guest_i= d", type: "integer", length:
> 140 }
>=C2=A0 =C2=A0 =C2=A0},
>=C2=A0 =C2=A0 =C2=A0AttributeOverride::{
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0name: "name",
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0column: Column::{ name: "guest_n= ame", nullable: false, unique:
> true, length: 240 }
>=C2=A0 =C2=A0 =C2=A0}]
> )]
>
>
> #[AttributeOverrides([
>=C2=A0 =C2=A0 =C2=A0AttributeOverride::{
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0name: "id",
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0column: Column::{ name: "guest_i= d", type: "integer", length:
> 140 }
>=C2=A0 =C2=A0 =C2=A0},
>=C2=A0 =C2=A0 =C2=A0AttributeOverride::{
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0name: "name",
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0column: Column::{ name: "guest_n= ame", nullable: false, unique:
> true, length: 240 }
>=C2=A0 =C2=A0 =C2=A0}]
> )]
>
> --
> Erick

We already have named arguments, which gives nearly the same syntax.=C2=A0 = Writing directly to properties like that makes no sense in a language that = has class-private properties and internal constructors.=C2=A0 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.=C2=A0 Yet another constructor-invoke syntax on top o= f that would offer nothing.

--Larry Garfield

--000000000000f82407061a548b1e--