Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:123539 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 EA4031A009C for ; Fri, 7 Jun 2024 16:03:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1717776304; bh=9H8TInbeDWjPcZ9wpu/UF5u6d3/aCVEngKUbWnvzm+w=; h=From:Date:Subject:To:From; b=PXfUw4udrT1kiJnKufbMQRKq7HJGT1Fv8L/KCrl+lqi2SUbQDzNH3P65w55cYPZxo 4l3TOF4gDCpLPU5x8iJpA11zwPYgx5bPXJvDBLP3EQUs2B6gA1WiXRlUNX4llfsKTL L7oES6pUUXWrIx7j2TmAjwyCDXbD6R/uAnut8TtlKZY4GXVpXHbrz++glls136s+Y0 T0rAkCsh34hF3C73wy8ho0dTMM/o66Zxuc7TMyvhKQbaDW0VqxzoHLqH5RFCx7V23N NuL6lac4ywZLODdtUsKNWbk6Wk5VIXTJO5UDmkiulc51eQqFlFyYSKEUzLKk37QSto sdP9kqAe+5mgQ== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 085A0180079 for ; Fri, 7 Jun 2024 16:05:04 +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-f170.google.com (mail-lj1-f170.google.com [209.85.208.170]) (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 16:05:03 +0000 (UTC) Received: by mail-lj1-f170.google.com with SMTP id 38308e7fff4ca-2e73359b979so27273101fa.1 for ; Fri, 07 Jun 2024 09:03:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1717776236; x=1718381036; darn=lists.php.net; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=vPJ/3U9EDawhWhPzOlQPUywAht/nfbk9k60Lkw3gBu4=; b=PW71dqgYbbU11uB3npPjGy/g9xa0cCXxiU37W26aNsty1VS+sxpX92NlMP7o1v9DY2 bk8dlbHnu9/W7jPBt5Vp7/QEzHozcCikvAWeLnAJhylKEC7QDy1IrXBu6Ifr8hdDs2ef 1giF2K9gZ2DK0VZDBEnMyUwXsJcYUn1Cq00rgMHJ2Jik4nAdQV3/3k0BdmnLXzeEYVty mi1visQNttm5bzM1c4e5UrI+VhcZE2aYYQ4KRShMZh/cTfKXXshq1yIqgPE75mH5TIPG fZplLR5wnA50brEE5T+6G79O4nomvru7DnGUgU38J5KqKMQPvaRkj9RGNVDE2GsI0mxt rVIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717776236; x=1718381036; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=vPJ/3U9EDawhWhPzOlQPUywAht/nfbk9k60Lkw3gBu4=; b=VplFHCmJARa7LizwWEjzogKs02e556hpv2XXIM5pWBaVUZqtUNGBS5AMdP3j6DsXpM PfH1NxiJdYyXdXYCr/evUtFEvI8dtbomkOQ9pYoHc6/Zz3fEaNujcvk1xTgYg1qAuT1R Wr62j4o4sdPjlmW9Du4WX6M3V8fHv7FwHlv+1XEGMBm7M+JmQ70/GQTRXgqj4+IY3ebB lRieKmmnHTQFT6O9oZp5xkYeUVGnZc3TqhGnwOnbU9Su+OCDSFkxhwD6KmcknkVGKqxl nJISvihsk9Qmofc/fOFEgFg9HPZpJIH/1urcrg9jpGLZWCZz4r6LcNlYMJitAPOwhGFC cL4w== X-Gm-Message-State: AOJu0YwABYhmsGNpUETtLrFyZLmBtI0/HfvyIMOlL888ZcoPUrZQ84UH +Eq3RQZ3vKv+o+J3gK3FFj2hn2kyM4z92FH7Dd7TM0A5uiL3ljlzmvHBn4EDGBAk8jNY8QEXBKO v7PGoUcxFnxWU8SpQ+6XDl8gqU052jt5WM2E= X-Google-Smtp-Source: AGHT+IG3epNovlvQqcabj47BeyDCPBPeJ3A3XBzakPRvrn6+ZqCla+ZxXSdZyc4TIOIMbqlZpY5R9ef2Y6A4SAUws/s= X-Received: by 2002:a2e:300b:0:b0:2ea:e98e:4392 with SMTP id 38308e7fff4ca-2eae98e4777mr10864091fa.27.1717776236086; Fri, 07 Jun 2024 09:03:56 -0700 (PDT) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net MIME-Version: 1.0 Date: Fri, 7 Jun 2024 18:03:44 +0200 Message-ID: Subject: [PHP-DEV] RFC proposal : "new" keyword shorthand To: internals@lists.php.net Content-Type: multipart/alternative; boundary="0000000000005b1897061a4ef2a0" From: condaminet.benoit@gmail.com (=?UTF-8?Q?Beno=C3=AEt_Condaminet?=) --0000000000005b1897061a4ef2a0 Content-Type: text/plain; charset="UTF-8" Hello, Following the RFC process, I'm sending this to propose a PHP change. More precisely a new zend language token. This is somehow linked to the recently accepted RFC called "new MyClass()->method() without parentheses", the goal is to introduce a shorthand for the "new" keyword. *Motivations :* The new keyword sometime has a bad DX, for example when chaining Class instantiation like this : $foobar = new Foo( new Bar(), new Etc()); We can quickly have very long class object construction in some case. In lot of Framework, to improve DX, static function construct are often used to avoid the new keyword, some create additional object builders, etc. As a first try, I start updated code to completely make the new keyword optional, like in Dart language for example, but it require very big change, with lot of impact (collision with function). So here is *my proposal : * Add a "new" shorthand, using the tilde character : "~" I made a POC, and it works well, declaring a new language token T_SHORT_NEW that simply reuse ZEND_AST_NEW under the hood. Here are some example of what it may look like for userland, through some tests I wrote : --TEST-- New keyword shorthand --FILE-- b(); ?> --EXPECT-- I'm B Other with nested : --TEST-- New keyword shorthand encapsulation --FILE-- foo->name; ?> --EXPECT-- I'm foo in bar As a last word, just wanted to add it will work on nested Attribute too, so for example this nested Attribute used in Doctrine : #[AttributeOverrides([ new AttributeOverride( name: "id", column: new Column(name: "guest_id", type: "integer", length: 140) ), new AttributeOverride( name: "name", column: new Column(name: "guest_name", nullable: false, unique: true, length: 240) )] )] Will also work like this : #[AttributeOverrides([ ~AttributeOverride( name: "id", column: new Column(name: "guest_id", type: "integer", length: 140) ), ~AttributeOverride( name: "name", column: new Column(name: "guest_name", nullable: false, unique: true, length: 240) )] )] About implementation, it should'n have any impact on SAPI or extension, the new keyword will still exist, it's just a new shorthand. I think you get the point, is it something that some of you would be interested in? I would be happy to make a proper RFC proposal. Just registered a wiki account : benconda Thank you, -- Cordialement, Benoit Condaminet --0000000000005b1897061a4ef2a0 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hello,

Following the RFC process, I'= ;m sending this to propose a PHP change. More precisely a new zend language= token.=C2=A0

This is somehow linked to the recently acc= epted RFC called "new MyClass()->method() without parentheses"= , the goal is to introduce a shorthand for the "new" keyword.=C2= =A0

Motivations :
The new keyword= sometime has a bad DX, for example when chaining Class instantiation like = this :
$foobar =3D new Foo( new Bar(), new Etc());

=
We can quickly have very long class object construction in some = case.=C2=A0

In lot of Framework, to improve DX, st= atic function construct are often used to avoid the new keyword, some creat= e additional object builders, etc.

As a first try,= I start updated code to completely make the new keyword optional, like in = Dart language for example, but it require very big change, with lot of impa= ct (collision with function).=C2=A0

So here is=C2= =A0my proposal :=C2=A0

Add a "new"= ; shorthand, using the tilde character : "~"
I made a P= OC, and it works well, declaring a new language token=C2=A0T_SHORT_NEW that= simply reuse=C2=A0ZEND_AST_NEW under the hood.=C2=A0

<= div>Here are some example of what it may look like for userland, through so= me tests I wrote :=C2=A0
--TEST--
New keyword shorthand
--FILE--
<?php
class A {
public function b() {
echo "I'm B";
}
}

~A()->b();

?>
--EXPECT--
I'm B=
Other with nested :=C2=A0

<= div style=3D"color:rgb(8,8,8)">
--TEST--
= New keyword shorthand encapsulation
= --FILE--
<?p= hp
class Foo {<= br> public func= tion __construct(
public string $name
) {}
}
class Bar {
public function _= _construct(
= public Foo $foo
) {}
}=

$bar =3D ~Bar(~Foo("I&= #39;m foo in bar"));
echo $bar->foo->name;

?>
--EXPECT--I'm foo in bar
As a last word, just want= ed to add it will work on nested Attribute too, so for example this nested = Attribute used in Doctrine :=C2=A0

#[AttributeOver= rides([
=C2=A0 =C2=A0 new AttributeOverride(
=C2=A0 =C2=A0 =C2=A0 =C2= =A0 name: "id",
=C2=A0 =C2=A0 =C2=A0 =C2=A0 column: new Column= (name: "guest_id", type: "integer", length: 140)
=C2= =A0 =C2=A0 ),
=C2=A0 =C2=A0 new AttributeOverride(
=C2=A0 =C2=A0 =C2= =A0 =C2=A0 name: "name",
=C2=A0 =C2=A0 =C2=A0 =C2=A0 column: n= ew Column(name: "guest_name", nullable: false, unique: true, leng= th: 240)
=C2=A0 =C2=A0 )]
)]

Will also w= ork like this :=C2=A0
#[AttributeOverrides([
=C2=A0 =C2=A0 ~At= tributeOverride(
=C2=A0 =C2=A0 =C2=A0 =C2=A0 name: "id",
= =C2=A0 =C2=A0 =C2=A0 =C2=A0 column: new Column(name: "guest_id", = type: "integer", length: 140)
=C2=A0 =C2=A0 ),
=C2=A0 =C2= =A0 ~AttributeOverride(
=C2=A0 =C2=A0 =C2=A0 =C2=A0 name: "name&quo= t;,
=C2=A0 =C2=A0 =C2=A0 =C2=A0 column: new Column(name: "guest_nam= e", nullable: false, unique: true, length: 240)
=C2=A0 =C2=A0 )])]

About implementation, it should'n have= any impact on SAPI or extension, the new keyword will still exist, it'= s just a new shorthand.

I think you get the p= oint, is it something that some of you would be interested in? I would be h= appy to make a proper RFC proposal.=C2=A0

Just reg= istered a wiki account : benconda

Thank you,=

--
Cordialement,
Beno= it Condaminet
--0000000000005b1897061a4ef2a0--