Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:123047 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 791AD1A009C for ; Mon, 8 Apr 2024 21:11:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1712610714; bh=3eP7gRewhwhsYnX3/kr8BmH9nAbVC8oakE1IKPvmNDc=; h=Date:Subject:To:References:From:In-Reply-To:From; b=C9kRWVI3Pq5/f1XpdBYY9k6TGo62yfblQOEHSgEL8V6BkpQAJqzvvRSbSBaw4zF4A atvDzA7TKJMO82n7ImmsisaU8IscuoJ7EMjxSfBuFG6vJpyA8VHuMu09EznAQjfn14 jGDSbh5vrrFz6Nc0VTUwdDYlrGZ+qUc3kdGnrc6WoEPKlH9WgJe0hOQHNQGFrxJ/Cr FWWCqyIMVx3MqyJLaZdwCRqLXnQVnUSFuiBSJK9P8zAZj9gFLi49ere3SO/MhrLfkb I5+t0bgRtVKtOBJ31V82pg0gTIzZd3LpJRnpp0p8gyPzTBuHSA5kDr2pT9FX9whWZ/ j+KuJU5sfsBLw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 939C6180041 for ; Mon, 8 Apr 2024 21:11:53 +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.8 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DMARC_MISSING,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-wm1-f42.google.com (mail-wm1-f42.google.com [209.85.128.42]) (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 ; Mon, 8 Apr 2024 21:11:52 +0000 (UTC) Received: by mail-wm1-f42.google.com with SMTP id 5b1f17b1804b1-4169b7f71e4so2576935e9.3 for ; Mon, 08 Apr 2024 14:11:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=scriptfusion-com.20230601.gappssmtp.com; s=20230601; t=1712610680; x=1713215480; darn=lists.php.net; h=in-reply-to:from:content-language:references:to:subject:user-agent :mime-version:date:message-id:from:to:cc:subject:date:message-id :reply-to; bh=19Hf6mZ7jsxL0nhMOs8VQkHf00n4sTDT5egl4LHvCjg=; b=keDXX/YjrXSg1dAL9krORn7A6y2bgvPEVG39vfgUVK6wHCKjhyxYpwextvXRBRObRg S65fPK4LnV2XU+iB5YacLyjF4Ct+RMAWNGGdxMgrd+V6q4EL+JXPMFnYMEcv4wz7uMgC g340LPYvAm1ccuGgNH/Gw3hqJFxgo2vXsfTX0eFbYJL6o07IpOF/9t156+Mt24Te32fu SEZH5diJiqU4fgBLg7wanwYqNJh+coAMDVM94YGtb4plnwE5ISeqMsUi/zuAotzxNwov Kh6k2FJmL2HdHbfm1jqwJc1Z+rEGhaX4F6KkvQG68g3fY+xcWX+jcSgFxSKB9Pgme/Ve +aBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712610680; x=1713215480; h=in-reply-to:from:content-language:references:to:subject:user-agent :mime-version:date:message-id:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=19Hf6mZ7jsxL0nhMOs8VQkHf00n4sTDT5egl4LHvCjg=; b=REU6HAZXynBvY2Ifjb3nDNw335ca0leAugS+rZGE+bHSQfEsRqZtokygiM6Iiv1+pt 0KJ8ltbWw6FBAeLL66IuDccdPHXb3rF5tshCxIBDJWCEbY0LsFC51KmbHuIOmSGpb8F5 xAOMpXyFDLrrWfe4pZmesvURHmMCxVyNaOFjl9hXo4ZZFrabsu6imYIryIBNiXns2P2Y Vfe1j2hKhH1lNvjBCByaWuNKN48nHxhniI3gVxlRRlsxRarG/6ae1FJe/m5+c9pK6XSp /KFCE5Gsrbw6HHxOePVCm74u897dMthciwaKEpV5EX1vbQdSqqXEPYuwssjPSaY1Ryyr OaVw== X-Gm-Message-State: AOJu0YxzGkMTKShvV8SMA8nzLaxE6IciHfrcFegKVRqKCK5iThgRFQ31 zsFKdgfkvloZJtiNhVG0rQXjQYmtNbKb/pKgr4vkTvaO/agJMsK/anuGP9bi2Ygjd0janT679JK oZx0= X-Google-Smtp-Source: AGHT+IFmkKgypoWAaQ5F6YiQ5ScRS1mfMOVuI5XtRdUKb63V3F7rjZ6iz3ENi0en/2jvbI85Vqnu+A== X-Received: by 2002:adf:e60b:0:b0:343:a64c:7c55 with SMTP id p11-20020adfe60b000000b00343a64c7c55mr7671256wrm.50.1712610679637; Mon, 08 Apr 2024 14:11:19 -0700 (PDT) Received: from ?IPV6:2a01:4b00:bf09:5101:6cee:8fcc:f1a4:edfe? ([2a01:4b00:bf09:5101:6cee:8fcc:f1a4:edfe]) by smtp.googlemail.com with ESMTPSA id z15-20020a5d4c8f000000b00343daeddcb2sm9906689wrs.45.2024.04.08.14.11.19 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 08 Apr 2024 14:11:19 -0700 (PDT) Content-Type: multipart/alternative; boundary="------------7LDLwlIa0WgD7Wvh8JMwhuQu" Message-ID: <01f2ba65-7d2e-4e9c-a173-bc9149f05502@scriptfusion.com> Date: Mon, 8 Apr 2024 22:11:17 +0100 Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PHP-DEV] [RFC] [Discussion] new MyClass()->method() without parentheses To: internals@lists.php.net References: Content-Language: en-GB In-Reply-To: From: bilge@scriptfusion.com (Bilge) This is a multi-part message in MIME format. --------------7LDLwlIa0WgD7Wvh8JMwhuQu Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Hi Valentin, You don't need me to tell you how popular your PR is, since it's the single most emoji'd open PR by a wide margin, but this is something that has bugged me since the parser improvements in 5.4. I even remember asking Nikita if it was possible to not have to wrap `new Class` in parens to dereference it, and he said it was, but just didn't do it for whatever reason. It's frustrating using a PHP REPL (e.g. Boris, PsySH) and wanting to write `new Class->foo()` only to have to backtrack and add the parens, because it's not natural (for me) to think in terms of the parens ahead of time. Even in the editor, it's the same experience; I often find myself backtracking to add the parens. Perhaps this seems like a small thing to some people, but for me this could be the sole reason to day-1 upgrade to 8.4. But I have no voting privileges so I can only offer you my thanks. Thanks for this! Cheers, Bilge On 08/04/2024 07:08, 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 > > > -- > > Best regards, Valentin > --------------7LDLwlIa0WgD7Wvh8JMwhuQu Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit

Hi Valentin,

You don't need me to tell you how popular your PR is, since it's the single most emoji'd open PR by a wide margin, but this is something that has bugged me since the parser improvements in 5.4. I even remember asking Nikita if it was possible to not have to wrap `new Class` in parens to dereference it, and he said it was, but just didn't do it for whatever reason.

It's frustrating using a PHP REPL (e.g. Boris, PsySH) and wanting to write `new Class->foo()` only to have to backtrack and add the parens, because it's not natural (for me) to think in terms of the parens ahead of time. Even in the editor, it's the same experience; I often find myself backtracking to add the parens. Perhaps this seems like a small thing to some people, but for me this could be the sole reason to day-1 upgrade to 8.4.

But I have no voting privileges so I can only offer you my thanks. Thanks for this!

Cheers,
Bilge

On 08/04/2024 07:08, 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


--

Best regards, Valentin

--------------7LDLwlIa0WgD7Wvh8JMwhuQu--