Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:123070 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 42BA81A009C for ; Tue, 9 Apr 2024 19:40:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1712691670; bh=uOftkfDj/yLXgKRpZDhupr07Q4UX3204tWNRlTecaJo=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=NS9zOS2tjorhKtzpuhaW41jEtm8CIBRdxEgnat4w41HYlhxrhUISZdzvyZ8GvLRFF FibruE4opMNjqRX9BMvc7BwdRaoQWubKIZJUqUuckp1I5yOuSfsuiRgIvku/iSkhfv N1co08NoQiEiZ1SBbjDasxEZPlroUMaV2IHFWqIr+mbKg1d4y8VJnWmZRw2rOg6hXl rZOwDGKcijrjvGXNSe2v88BiaXSclk+Wuz5Q0QNLVhClliB2Hqj0IxIIJA2LNDYYwK XiC4YjaHusi/Tcbqq3MbdUkZV51PHhKke35VDmJPl6SizpekHGKpP/b7aCPPb3ejXO KH69Nl2LeG8LA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id D54F61804BF for ; Tue, 9 Apr 2024 19:41:09 +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: No X-Envelope-From: Received: from mail-lj1-f173.google.com (mail-lj1-f173.google.com [209.85.208.173]) (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 ; Tue, 9 Apr 2024 19:41:09 +0000 (UTC) Received: by mail-lj1-f173.google.com with SMTP id 38308e7fff4ca-2d6c9678cbdso78428371fa.2 for ; Tue, 09 Apr 2024 12:40:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1712691636; x=1713296436; 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=qBSTSWHsYcyc3XzxCKc2wnQhdiLxhXag6CScSs1DeM0=; b=iPqTiJcYfq90cTGarVMk25gnyPk7uElrh8Ikr5R4uSRJRZzf1EBrW9tBmdBvpHslms id4wb7GHfO5MwlVT5cITf4NrE0qDf+6t2qxkoCr5HYnyN93U/4Ty8SyQH9FGsCPwxs6E DFCMTCPKxZs/CXuS8YFuX/9+h7qRqpiChVpd/+eo3AhIZWwHhLJiG+PH2Euo055F9h7c AeRvBmn+/7tczWmPbW46/KDqG00PVX5jkzAwWO97Mst+3qbIjR00PVOAVbEvdcaGsWtl UECDHNMLefpbIeqKA5g4cGNvll4zmNKm8lUC4nuh0D3hiXEaakogLsMqwS1XJkqZc7xg owww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712691636; x=1713296436; 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=qBSTSWHsYcyc3XzxCKc2wnQhdiLxhXag6CScSs1DeM0=; b=N+SijNnmmxftk+1I9rIzlLnw+42ChaLukD15+sj2W3cQw2IIQju+uZ4WWQtX3nNMS0 t/2ZDb+70SdvSEzWMfh7mNwhLceV2WEzscOWnQS2kg8pgSQksR+BeYKcHacuJCRUd4qa 2XF7t+UlYODGuFms2ThVkxMdgnHSHCd9vzaSxb1FONyLxPcRU9ypBGX2eVKVKofYRHq3 7ueTSxBRY1mrUGARPM2P9x2nDzmPTQRkWCPvuQh2jNBgmfEFQF2tNzkWeMVITNrEJFI0 vwWCBZQj1YS/sFm0FVtuVwXMK3jqaiILWouaGw1EE3bfuKoycWEx/jVQpAeRcSZ+CA1X +5Pg== X-Gm-Message-State: AOJu0YxOYqIC/twVXhLfceCP336phM9t+CY8XAb0Edoc5LbDXBxm3xJQ zyfhjtvDSN9UD39y45ymuWZ8JERj9EihpOeo1SyalvmOZNwzbj2Sm0vyhlMFWLUxUCdG7qaTZr8 nrmQt/thF/cHqvS2qsXv/XI7YrdWe82lKZFyb X-Google-Smtp-Source: AGHT+IHBFURNWkE594BUPQeBkHrpj25Bu/H0JYqksuRvH5+1viXr2/c6nt2UZtG1D2hH5TWA9MdnaimOJ9x9GWysWMU= X-Received: by 2002:a2e:934d:0:b0:2d8:517f:1a22 with SMTP id m13-20020a2e934d000000b002d8517f1a22mr474207ljh.25.1712691635403; Tue, 09 Apr 2024 12:40:35 -0700 (PDT) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net MIME-Version: 1.0 References: <0466054f-bbec-47fd-8452-e848ebec7ec9@app.fastmail.com> In-Reply-To: <0466054f-bbec-47fd-8452-e848ebec7ec9@app.fastmail.com> Date: Tue, 9 Apr 2024 22:40:24 +0300 Message-ID: Subject: Re: [PHP-DEV] [RFC] [Discussion] new MyClass()->method() without parentheses To: Larry Garfield Cc: php internals Content-Type: multipart/alternative; boundary="00000000000089c5910615af1804" From: udaltsov.valentin@gmail.com (Valentin Udaltsov) --00000000000089c5910615af1804 Content-Type: text/plain; charset="UTF-8" > > On Mon, Apr 8, 2024, at 6:08 AM, Valentin Udaltsov wrote: > > Hello internals, > > > > > > > > I would like to propose a syntax change for PHP 8.4 that allows to > > immediately access instantiated objects without wrapping the expression > > into parentheses. > > > > > > > > This was requested and discussed several times, see: > > > > - https://externals.io/message/66197 > > > > - https://bugs.php.net/bug.php?id=70549 > > > > - https://externals.io/message/101811 > > > > - https://externals.io/message/113953 > > > > > > > > Here's what you will be able to write after this change: > > > > ```php > > > > class MyClass > > > > { > > > > const CONSTANT = 'constant'; > > > > public static $staticProperty = 'staticProperty'; > > > > public static function staticMethod(): string { return > 'staticMethod'; } > > > > public $property = 'property'; > > > > public function method(): string { return 'method'; } > > > > public function __invoke(): string { return '__invoke'; } > > > > } > > > > > > > > var_dump( > > > > new MyClass()::CONSTANT, // string(8) "constant" > > > > new MyClass()::$staticProperty, // string(14) "staticProperty" > > > > new MyClass()::staticMethod(), // string(12) "staticMethod" > > > > new MyClass()->property, // string(8) "property" > > > > new MyClass()->method(), // string(6) "method" > > > > new MyClass()(), // string(8) "__invoke" > > > > ); > > > > ``` > > > > > > > > For more details see the RFC: > https://wiki.php.net/rfc/new_without_parentheses > > > > Implementation: https://github.com/php/php-src/pull/13029 > > I always thought there was some technical parser reason why this wasn't > possible. Maybe that was true in 5.x but isn't anymore? > > I cannot speak to the implementation, but I'm all for the change itself. > > --Larry Garfield > Hi, Larry! The grammar is compiled with no warnings, so it is definitely possible now. I also added a lot of tests that guarantee that existing behaviour is preserved and new syntax works as expected. Marco, Bilge, Levi, Larry, thank you for your positive feedback on the RFC. --00000000000089c5910615af1804 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
On Mon, Apr 8, 2024, at 6:08 AM, Valentin Udaltsov wrote= :
> Hello internals,
>
>
>
> I would like to propose a syntax change for PHP 8.4 that allows to > immediately access instantiated objects without wrapping the expressio= n
> into parentheses.
>
>
>
> This was requested and discussed several times, see:
>
> - https://externals.io/message/66197
>
> - https://bugs.php.net/bug.php?id=3D70549
>
> - https://externals.io/message/101811
>
> - https://externals.io/message/113953
>
>
>
> Here's what you will be able to write after this change:
>
> ```php
>
> class MyClass
>
> {
>
>=C2=A0 =C2=A0 =C2=A0const CONSTANT =3D 'constant';
>
>=C2=A0 =C2=A0 =C2=A0public static $staticProperty =3D 'staticProper= ty';
>
>=C2=A0 =C2=A0 =C2=A0public static function staticMethod(): string { ret= urn 'staticMethod'; }
>
>=C2=A0 =C2=A0 =C2=A0public $property =3D 'property';
>
>=C2=A0 =C2=A0 =C2=A0public function method(): string { return 'meth= od'; }
>
>=C2=A0 =C2=A0 =C2=A0public function __invoke(): string { return '__= invoke'; }
>
> }
>
>
>
> var_dump(
>
>=C2=A0 =C2=A0 =C2=A0new MyClass()::CONSTANT,=C2=A0 =C2=A0 =C2=A0 =C2=A0= // string(8)=C2=A0 "constant"
>
>=C2=A0 =C2=A0 =C2=A0new MyClass()::$staticProperty, // string(14) "= ;staticProperty"
>
>=C2=A0 =C2=A0 =C2=A0new MyClass()::staticMethod(),=C2=A0 // string(12) = "staticMethod"
>
>=C2=A0 =C2=A0 =C2=A0new MyClass()->property,=C2=A0 =C2=A0 =C2=A0 =C2= =A0 // string(8)=C2=A0 "property"
>
>=C2=A0 =C2=A0 =C2=A0new MyClass()->method(),=C2=A0 =C2=A0 =C2=A0 =C2= =A0 // string(6)=C2=A0 "method"
>
>=C2=A0 =C2=A0 =C2=A0new MyClass()(),=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 // string(8)=C2=A0 "__invoke"
>
> );
>
> ```
>
>
>
> For more details see the RFC: https://wiki.php.= net/rfc/new_without_parentheses
>
> Implementation: https://github.com/php/php-src/pull/13= 029

I always thought there was some technical parser reason why this wasn't= possible.=C2=A0 Maybe that was true in 5.x but isn't anymore?

I cannot speak to the implementation, but I'm all for the change itself= .

--Larry Garfield

Hi, Larry! The grammar is compile= d with no warnings, so it is definitely possible now. I also added a lot of= tests that guarantee that existing behaviour is preserved and new syntax w= orks as expected.

Marco, Bilge, Levi, Larry, thank= =C2=A0you for your=C2=A0positive=C2=A0feedback on the RFC.
--00000000000089c5910615af1804--