Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:129377 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 lists.php.net (Postfix) with ESMTPS id 8AFE51A00BC for ; Fri, 21 Nov 2025 18:10:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1763748654; bh=yAUjNfX9vtdIvVOKR91ECnFpVkw379caE8HNeJ4nHIU=; h=Date:From:To:Subject:In-Reply-To:References:From; b=NQ3EWKHSKuceoy//r6atZIxzVexHCSgyj+bQQoOhHnhYe6Pxzclwb1Z8FCtZJDF8D 3gSB/5zmceoPn24SIyEaawfPO/REvVSwZ7S86/oyocBg68A9eNUoXExZ/1anp73O5f 5rgRiR+zYsrbaoCeDSm3Oe7Gtk6oEpzNYbRhK8EOQeotXlcqGZcqgDUvBeqSCCn1Du V84aNhdM+m3nSGIup31FrcSqnxJp1eup/i+6jJka6Se7caY7e0+CObYpzND0HNxMWV T4hj8EAiUpK+PEYFwa4OPR0EBCqquszp4RT7oeVc6I8JykJ7cg7wyyo1MV2VFP4Ldx j7qVxwjFuFkQw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 51B42180041 for ; Fri, 21 Nov 2025 18:10:53 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_MISSING,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: No X-Envelope-From: Received: from fhigh-a2-smtp.messagingengine.com (fhigh-a2-smtp.messagingengine.com [103.168.172.153]) (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, 21 Nov 2025 18:10:52 +0000 (UTC) Received: from phl-compute-06.internal (phl-compute-06.internal [10.202.2.46]) by mailfhigh.phl.internal (Postfix) with ESMTP id 8115814001F1 for ; Fri, 21 Nov 2025 13:10:47 -0500 (EST) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-06.internal (MEProxy); Fri, 21 Nov 2025 13:10:47 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rwec.co.uk; h=cc :content-transfer-encoding:content-type:content-type:date:date :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm3; t=1763748647; x=1763835047; bh=yAUjNfX9vtdIvVOKR91ECnFpVkw379caE8HNeJ4nHIU=; b= XYV6n5TtQyABdi27tCHue6X9D6pFW4oxHiDL4hQJIbBrxpFuruKwWPLJcodU7h4l bzsH9j3g8eo+mpESKKiLQ8ijUti3CW6O28hW8PcSW0BoMj9lu3kR0+AyNPmJuw5z yo9aWSsqiZ1UjrJBrzCRPe81wIczQcf1etGCwTT0Ld1n7U14YlZ7v/GVQDAkqXPo nXt5sxW0OzYZmeoDZKkqTMhSnFRMkIgofdqZ20QCIHrXcvBWN6435dxh17Q8kE4C tQO7xtuMos1yehk/sdKW//tAM5Ud1Hm4GZrT0uottdEus0zkYj1Qzbmle7ihx+oY a+8u/TwPTOz64kF8WP2lIw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm3; t=1763748647; x=1763835047; bh=y AUjNfX9vtdIvVOKR91ECnFpVkw379caE8HNeJ4nHIU=; b=Yi2xuDxPrqTc/VPYf 7eeOBhaN8v4TlIVva3Qmd1T03LI3U4/MpDNLRtAgmaGtJhWhVb0ixuYy3fvqfdBa E6pdE++VcKlNMLwLuA/vKWXnYZWYXaCQP4us5WA/BTpVP7glfzSgATE5wRuv4xvL 6Mkm6ARZYRu5uaKBYJ/0gGR2FX7OotzK5ZRW/kwQ88UJa1+Zd32xaikYZ0weSAjV gpZVUagLyI6E3aku1bssmUuZdQ0otvt5y+BCjKoZTjGmUuFKA1Yl3SRtwtw6CXVm BBqX1QQY33o8Y4SgZRBOqs2bWPhDHIyB5nJbjf6DIiYblByVLKodOXuyOvcZT0VW odePw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtdeggddvfedtieegucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceu rghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujf gurhepfffhvffufggjfhfkgggtgfesthhqmhdttderjeenucfhrhhomhepfdftohifrghn ucfvohhmmhhinhhsucglkffoufhorfgnfdcuoehimhhsohhprdhphhhpsehrfigvtgdrtg hordhukheqnecuggftrfgrthhtvghrnhepledvueehtdehudduleefhffgjefhffdvleej fefgueeigfeigfdvhefhfeeuvddvnecuffhomhgrihhnpehphhhprdhnvghtnecuvehluh hsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepihhmshhophdrphhh phesrhifvggtrdgtohdruhhkpdhnsggprhgtphhtthhopedupdhmohguvgepshhmthhpoh huthdprhgtphhtthhopehinhhtvghrnhgrlhhssehlihhsthhsrdhphhhprdhnvght X-ME-Proxy: Feedback-ID: id5114917:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Fri, 21 Nov 2025 13:10:46 -0500 (EST) Date: Fri, 21 Nov 2025 18:10:45 +0000 To: php internals Subject: Re: [PHP-DEV] First-class constructor callables User-Agent: K-9 Mail for Android In-Reply-To: References: Message-ID: <14011964-49CB-4186-9109-6C90FC1ADBBE@rwec.co.uk> Precedence: list list-help: list-unsubscribe: list-post: List-Id: x-ms-reactions: disallow MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable From: imsop.php@rwec.co.uk ("Rowan Tommins [IMSoP]") On 20 November 2025 13:19:09 GMT, Valentin Udaltsov wrote: > >I'd like to explore the possibility of adding a first-class callable synt= ax >for object constructors: > >``` >$factory =3D new Foo(=2E=2E=2E); >``` > >The idea is that this expression would produce a Closure which, when >invoked, calls the constructor with the provided arguments: > >``` >$factory =3D new Foo(=2E=2E=2E); >$object =3D $factory($arg1, $arg2); >``` Something worth clarifying here is that what you want is not just to *call= the constructor*, but to *create the object*=2E In some languages, that's = the same thing - there's a base object constructor which has to be called -= but in PHP, the constructor itself is just a callback hook, called *after*= the object exists=2E And that's where the complexity comes in: "new Foo" isn't a function call,= it's an interpreter operation=2E Here is Nikita's explanation of the issue in the First Class Callable RFC = [Begin Quote] The new Foo() syntax is not considered a call, and as such also not suppor= ted by the new Foo(=2E=2E=2E) syntax=2E It should be noted that there is al= so no way to express object creation with traditional callable syntax, and = it is thus also not supported by Closure::fromCallable()=2E The general expectation is that new Foo(=2E=2E=2E) would be creating a new= instance of Foo on each call, rather than creating a single instance of Fo= o and then repeatedly calling the constructor=2E To support this, it would = effectively be necessary to generate a trampoline function of the form fn(=2E=2E=2E$args) =3D> new Foo(=2E=2E=2E$args) and acquire a callable to that trampoline instead=2E While certainly possi= ble, this takes a step backwards from the straightforward semantics of the = foo(=2E=2E=2E) syntax for ordinary calls=2E [End Quote] Rowan Tommins [IMSoP]