Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:126831 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 AFC4F1A00BC for ; Tue, 18 Mar 2025 21:53:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1742334678; bh=c9kfZQmZit2cjVBfgHbhaN9BoadAYuvMTU3DlmW3uIs=; h=Date:From:Subject:To:References:In-Reply-To:From; b=F2QLbJWir0ihFlO6yDCt0NkwUeKxj99Bau5S9BDnIqhQv6d/X8e+S1/p+VIe5JDON JcMglHCym8uLXoL+zQSeeOsR5VsQAz6TB9YgqEwuerwznxzZYrrXLOwNwgIP9CelYV 4vGWYi/XNA8xUZFdn1zepaLr6Hf94YUBD/NVXRrksOmBIPqjKA8tDw9zFHD46Xp5nb bmTSO1S7866j6qNnqR5H56GNSD9bvhMVBEZB30EF6djtdIyCj9NVSIpRXsx6ObGcoK Xl3+BvlitgrVhDqeTDAEzcVpFlNkyQIhPTtfe4O9hcDiRCklRiY/mR0hqBJJhQ65BY SoQ2+DIcIlM/w== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id D1F76180080 for ; Tue, 18 Mar 2025 21:51:16 +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=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_MISSING,RCVD_IN_DNSWL_LOW, SPF_HELO_PASS,SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from fout-a7-smtp.messagingengine.com (fout-a7-smtp.messagingengine.com [103.168.172.150]) (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, 18 Mar 2025 21:51:16 +0000 (UTC) Received: from phl-compute-07.internal (phl-compute-07.phl.internal [10.202.2.47]) by mailfout.phl.internal (Postfix) with ESMTP id 62F221383159 for ; Tue, 18 Mar 2025 17:53:47 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-07.internal (MEProxy); Tue, 18 Mar 2025 17:53:47 -0400 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=fm1; t=1742334827; x=1742421227; bh=Y/w3nePnf0XXYT5dCbLXOgpMrMte1XAl0HqHHxO63Do=; b= RzHuIzwv0fkKyJv12sOcuwda7knyK/BLmDjtpU8Wvk/Djv9qR3p+7SuKzbIueswn ZRP4RUrPKIvy4CSnqiVDdV9U93j2ldvbjHa5SzAn9nttXA07wj8gmFcuvhWL5UdD QA9AsTVkG5XqRtA4SVqmP9f6QZZtghTxQQbOQUrhI+nrr0bRufvOJXo1ME58WUMP wrjvAJ1vxTBDK0E2y6xAcqyK5Ysjva9uOOQ30LvHRWyMW/yX1a1KoiH9bndSRW+l kupgKVuTKr2ZbSMMfO/Ue/vNA37DDnHnBdsGN8sgb47KRmodSaZXQECsxAZfy8yk cEhmtiWRM2DpMumpKMeuBg== 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=fm1; t=1742334827; x=1742421227; bh=Y /w3nePnf0XXYT5dCbLXOgpMrMte1XAl0HqHHxO63Do=; b=pDuCU0rkOmzKZnWga kwR5AtfCiH+WvjghBju+KK+Fv2x6wkzO9vRoWfCKspjNnkJqpNrEBBnT0XH2Jjin HCAR1pJajOiGutcLSiCuA+3uNx3Khykbxac33v2moGDzoPvwZNjqeU0ecTfq4nyB K9jyby5t5zRerIh5vHEU3hQ+e0Z0QFHy3j10tl3IXsUC32qsuegNyGDcIp6sWEQy C1U4tgUAn9Jg7Fr17m6+KAp+dSZnCAuWsXSO6XJ5Dv5Zsdt9PZNDfohrlIEP9fq5 kFbypEpoy93QQ4jiO2QUs3drVp4odOsvQyhF3ba76JPGNK/d2bTJMU5JhlTFuVJG zHF4Q== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgddugeefheejucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggv pdfurfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpefkff ggfgfhuffvfhgjtgfgsehtkeertddtvdejnecuhfhrohhmpedftfhofigrnhcuvfhomhhm ihhnshculgfkoffuohfrngdfuceoihhmshhophdrphhhphesrhifvggtrdgtohdruhhkqe enucggtffrrghtthgvrhhnpeejgfegfffhledttddujeefueevuddvjefhvdffudffteej veeuudetjeekvddtjeenucffohhmrghinhepphhhphdrnhgvthenucevlhhushhtvghruf hiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehimhhsohhprdhphhhpsehrfigv tgdrtghordhukhdpnhgspghrtghpthhtohepuddpmhhouggvpehsmhhtphhouhhtpdhrtg hpthhtohepihhnthgvrhhnrghlsheslhhishhtshdrphhhphdrnhgvth X-ME-Proxy: Feedback-ID: id5114917:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Tue, 18 Mar 2025 17:53:46 -0400 (EDT) Message-ID: Date: Tue, 18 Mar 2025 21:53:43 +0000 Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PHP-DEV] PHP True Async RFC - Stage 2 To: internals@lists.php.net References: <72bd5401-53a9-409f-ad45-687333401961@rwec.co.uk> Content-Language: en-GB In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit From: imsop.php@rwec.co.uk ("Rowan Tommins [IMSoP]") On 18 March 2025 08:22:18 GMT, Edmond Dantes wrote: >> >> spawning in a scope a "second-class citizen" if `spawn foo($bar);` >> > >Reminds me of *"post-purchase rationalization"* or the *"IKEA effect".* > >when effort has already been invested into something, and then suddenly, >there's a more convenient way. And that convenient way seems to devalue the >first one. That's not really what I meant. I meant that if you're learning the language, and see feature A has native and intuitive syntax, but related feature B is a method call with an awkward signature, you will think that feature A is more "normal" or "default", and feature B is "specialist" or "advanced". If we want to encourage people to think that "spawn in current scope" is the default, to be used 99% of the time, I guess that's fine. But if we want using scopes to feel like a "natural" part of the language, they should be included in the "normal" syntax. And if we have short forms for both on day one, I don't see any need to also have the long forms, if they end up needing slightly different semantics around closures and parameters. >> I'm confused - $scope->onExit() is already in the RFC, and I wasn't >suggesting any change other than the syntax. >> (Although I'm not sure if it should defer to coroutine exit rather than >scope exit by default?) >> > >Yes, that's correct. The onExit method can be used for both a coroutine and >a Scope. >As for the method name onExit, it seems like it would be better to replace >it with something clearer. I'm still confused why you started talking about how to implement "defer". Are you saying that "onExit" and "defer" are different things? Or that giving it dedicated syntax changes the implementation in some fundamental way? >> spawn call bar(...); >> > >It doesn't make sense because the arguments must be defined. As with any other callable, it would be called with no arguments. It was just an illustration, because the function_name(...) syntax is one of many ways of creating a callable in PHP. >> Is there a reason to redefine all of this and make fresh decisions about >what to allow? >> > >If we strictly follow syntax consistency, then of course, we need to cover >all possible use cases. > >But when I see code like this: > >```php > >spawn ($this->getSome()->getFunction())($parameter1, ...); > >``` > >I start seeing circles before my eyes. 😅 Sure, any flexible syntax lets you write subjectively horrible things. But like with allowing object keys and adding Async\Key objects, this isn't the place to redesign existing language features based on personal taste. If the feature is "you can put a function call here", let's not waste time writing a new definition of "function call" - the scope of this project is already big enough already! A great example of exactly this is the First-Class Callables RFC: https://wiki.php.net/rfc/first_class_callable_syntax > The syntax CallableExpr(...) is used to create a Closure object that refers to CallableExpr with the same semantics as Closure::fromCallable(). > CallableExpr can be any expression that can be directly called in the PHP grammar. That's pretty much the whole definition, because the implementation directly uses the existing function_call grammar rule. The only caveat is that calls using the nullsafe ?-> operator are forbidden - for reasons directly related to the feature, not because Nikita thought they were ugly. >spawn [with ()]; > ... >spawn test with ("string"); >spawn test(...) with ("string"); Only the second of these meets the proposed rule - `test(...)` is an expression which evaluates to a Closure object; `test` as an expression refers to a constant, which I'm pretty sure is not what you intended. If you allowed any callables, not just Closures, this would technically be valid: spawn "test" with ("string"); But most likely you'd still want a separate syntax for a direct function call, however you want to spell it: spawn_this_closure_ive_created_somehow function() { do_something(); do_something_else(); }; spawn_this_closure_ive_created_somehow test(...) with ("string"); spawn_this_function_call_without_creating_a_closure test("string"); Or forget callables, and anything that looks like it's trying to be one, because creating a Closure isn't actually the user's aim: spawn_this_function_call_without_creating_a_closure test("string"); spawn_these_statements_use_a_closure_if_you_like_i_dont_care { do_something(); do_something_else(); } -- Rowan Tommins [IMSoP]