Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:113953 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 72134 invoked from network); 5 Apr 2021 16:42:08 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 5 Apr 2021 16:42:08 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id ED53A1804E3 for ; Mon, 5 Apr 2021 09:40:56 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-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,SPF_HELO_NONE,SPF_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail.webkr.de (mail.webkr.de [78.47.173.34]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits)) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Mon, 5 Apr 2021 09:40:55 -0700 (PDT) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 1432F1A0FFE for ; Mon, 5 Apr 2021 18:40:52 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=webkr.de; s=dkim; t=1617640854; h=from:subject:date:message-id:to:mime-version:content-type: content-transfer-encoding; bh=rESRzAv7XHbDk9WHObEv7lZ8zsUPoJ2Gr+s6UqIDn/k=; b=lQT+baxEy70+rpjQGsOEIbLtRTqIDRvonuiYm8zfZk8sguYuSAJEXC63gcUbaFOIjlqG/8 lTWNHwd5jtc6drVc8ZSUMLqp7y6ypWuQlC2JLtW1qrJjlrfBSJkKJ25St7V6tB16+WmXZf 8J0tZ86sXWIwkfXaBwulo7WT1jv34GI= To: Date: Mon, 5 Apr 2021 18:40:49 +0200 Message-ID: <0b8301d72a3a$71045ca0$530d15e0$@webkr.de> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Thread-Index: AdcqOIdDRm+Kv5kgQMqeAN7vbD8lgQ== Content-Language: de X-Last-TLS-Session-Version: TLSv1 Subject: Raising the precedence of the new operator From: andre@webkr.de (=?iso-8859-1?Q?Andr=E9_H=E4nsel?=) I was wondering... PHP is the only language I know of where you have to write `(new Foo())->bar()` instead of `new Foo()->bar()`. This is particularly apparent with the builder pattern: $developer->drink((new Coffee())->withCream()->withSugar()); $logger->log((new LogMessage())->withMessage('Coffee was drunk')); Since `new Foo()->bar()` cannot (and probably should not) be used to "dynamically instantiate a new thing of the class name returned by function Foo()", it seems like it would be no problem to change the precedence rules so that `new Foo()->bar()` means "instantiate a new Foo and call bar() on it". It's currently a syntax error, so allowing it would be automatically compatible. Has this ever been discussed before?