Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:125916 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 8A4631A00BD for ; Wed, 6 Nov 2024 10:15:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1730888268; bh=AYomDfv9pmjvWDs0M4eEUmPQ0cNqcvmz96ucjk+39W8=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=RKhc2IPz1dqTKA8Q7BuhZSpSKnko3meFVafusJdMsWh+y14KRXI/0Nt2ptv2gc2ZZ d46axkcNYylcJVetxwQD2/81cua2r+EQIlxUN3FhiB6NjeJcbGIM6xUeQB41gV1WaM o4rpXB2csASctP70Da8PrTzsAGSVUge0POwaajBMPo7HHSN05XcGpNQKs1ZN6YPyaf myu3+3/+MgQ05OgHajgcYRp0Ayu1OpOm5io+71XGS/kE25FF1s81K0uY4jXxjG/UI0 GdlXfgbUHfcW2F+0Mjhr9lyBwRJw/0QQ/jQ14Tm+lowIEWhDx7mhZhV93ZPPyTRYnr ol1ryLihPfOeA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id A4728180074 for ; Wed, 6 Nov 2024 10:17:47 +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,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from chrono.xqk7.com (chrono.xqk7.com [176.9.45.72]) (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 ; Wed, 6 Nov 2024 10:17:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bastelstu.be; s=mail20171119; t=1730888113; bh=qHwn4wfK3JaFUDPufMw9GMNYi5qw+tvTXOLBvkSR7l8=; h=MIME-Version:Date:From:To:Cc:Subject:In-Reply-To:References: Message-ID:Content-Type:from:to:cc:subject:message-id; b=jvG/tRScLGsc1VKJEPyNVsJVsPOul5iLAEx1wsxqk9oJgcYH6cSFas8kMx+hNViBE ExFn1+Q1UqW2Agq8uZZOvcAcT61q9r5oc3SBg2stGyYJgocdIWkeZo/RzNAxIMUXuz eoVLMzhemKKy5CWYZwjAIFgqrI5rT3wVnEqkzc8m/+DOXdfRm9MfY5EbZnc/2a5Gut hsDo6d7VkCjziLnrM62UWThNScW81TYRRXQuInXtiLz7jihX6jvLBdrb/59MymYTcR CyokVjt9ddrgZqOe2Jwunranz6/l1KOulceQzUtxcuYxlO2yQHA6Psrb8xYSEVLQBu v4vehA/MGyfNw== Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 Date: Wed, 06 Nov 2024 11:15:12 +0100 To: Larry Garfield Cc: php internals Subject: Re: [PHP-DEV] RFC: Support Closures in constant expressions In-Reply-To: References: <15da4c13445d7e9c9d768c60c19768d4@bastelstu.be> <3b458165-406c-4b70-97bc-6e98d6c44c72@app.fastmail.com> <6f39dce9e6b0579baa51bc84cb8140b9@bastelstu.be> <219e4bbc0b94c35d2410fb640db6c477@bastelstu.be> <6bffc58a-b869-495e-9be8-0590822e6d79@app.fastmail.com> <2sPXJojAve1IIS8SoHTv2VumjKcVe0iTwygretTEfvf8KVMw_qPZf3vKUfC1GrOk979EvXmKm86igz06Dk6VpOkkMMeU5vYvB4qghjyuk6g=@gpb.moe> Message-ID: <34e82090b2b234b16fe9dc956d7b3c3c@bastelstu.be> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit From: tim@bastelstu.be (=?UTF-8?Q?Tim_D=C3=BCsterhus?=) Hi Am 2024-11-05 18:49, schrieb Larry Garfield: >>> My expectation is that it's confusing, and therefore we should simply >>> disallow it. Which roughly translates to detecting if a closure tries >>> to use an unbound variable statically. Which is probably more >>> difficult than I make it sound. :-) >> >> Which is why short closures are being disallowed. >> The value of it *is* limited, and the semantics of it are confusing. >> I am struggling to see why this is such a big deal. > > I suspect, since several people have asked about it, it's because most > of the use cases for having a default Closure value are going to be > short; the sort of short cases that short-closures and FCC are designed > for. If it's long, then you're probably better off moving it to a > private method and making a FCC reference to that private method the > default value instead. Even though the initial example is one that uses a default parameter value, we see the primary use case in supporting Closures in attribute parameters. That’s why that’s the use case mentioned in the first paragraph and that’s why all the snippets in the “Use Cases” section showcase attributes. > I'm not asking for a detailed description of the engine nuances of > detecting unbound variables. Just something along the lines of "this > would require detecting unbound variables, that's hard, so we'll save > that for later." Which is a level of detail I frequently do provide in > my RFC future-scopes. The extent of investigation I did regarding the implementation was verifying that “yes, it indeed does crash”, because you can’t build an implementation if you do not know what the expected behavior should be in the first place. It is not at all obvious how variable capturing (or rather: variables in general) should work from a semantic perspective, as you confirmed yourself (“it’s confusing, and therefore we should simply disallow it” [1]). We disagree with adding another special-case to PHP’s semantics by introducing a “non-capturing short closure” as a third type of Closure [2] and figuring out what the semantics of variables within const-expr should be is out of scope for this RFC. In any case, the “Constraints” section already explains why those constraints exist. Best regards Tim Düsterhus [1] My personal expectation for parameter default values would be that any previous parameter would be legal to access and capture. [2] Or fourth, if you consider FCC to be a type of Closure.