Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:129900 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 0A9CF1A00BC for ; Fri, 23 Jan 2026 16:50:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1769187031; bh=Ijx45JF92mr9cEWraJ84jtf7q8Lyw/aYch9J15WsZ0Y=; h=References:In-Reply-To:From:Date:Subject:To:From; b=jkT/MWDvK630gqXhGP9g2/R1p+nwh+/Ohw8I8+5c7EVFV3L1DtM8SgfdiGtb6JQH9 NUIkg18i2jQCAWBtegoqtWzZmjK2U9BgtVj3oSqSVUE6MT4P/8YjbUAgha+5ZYm7Ko GoW31iyviJjsGQQ1PYpe+qzZ+rY7kTdOjCmsqO0pwIwMGGOKHe+vzuiqSaOMFCpKOv vf5k3oF3uWXqyNEXxv7j79d9KVYaEwmYT1jhUDfRmE0gAn4iqg6YPXro1BLmBHuA5W pwrjHg7Z48Ax0Sf40cbLHJW+FvqUe9SkYTK439HQEMgmrLobc634myXuGMtoQu7r+3 3QvYR18ishk1A== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id BEB03180507 for ; Fri, 23 Jan 2026 16:50:30 +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=0.6 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_50, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS, FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: No X-Envelope-From: Received: from mail-qv1-f42.google.com (mail-qv1-f42.google.com [209.85.219.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 ; Fri, 23 Jan 2026 16:50:30 +0000 (UTC) Received: by mail-qv1-f42.google.com with SMTP id 6a1803df08f44-8887ac841e2so22486426d6.2 for ; Fri, 23 Jan 2026 08:50:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1769187024; cv=none; d=google.com; s=arc-20240605; b=Ax7wATLYN2qAWmvFzTm9VF2ZFH4u06xgbe41uEdFxpOo3mGJCE8AyLqlLKWldpyA9y 83K48/Iqls5y+up3xBULkns8ViLH69rgn4m5Ca/zTVV2oLCSh7o7kVmJVGkZ+FxWzdaN SygXaK9eT/0KAGesSPurUfB3wQQykjTnRkGIOx/0qPqLfUeJkFmUIw2AD77FYVEizl/r CNItC2d84oKkctQopuJZ4NQqEG75k2F10+9WdTyEp64gpzNIMvVBVyT7wDxfkBsskAJA AUdipEW3vRbwG7h4//Ds79vOor5R2KJ6Tr0Db4so8rPNKFGjrB+PD2rGUpLRyNKHjBe5 PoVQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=content-transfer-encoding:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=9n/swwelPOu2dShui6uF2pd742fw31/9wMx5nkLry1g=; fh=RnZ+4KjfdZdxwVfzmjFoBvUAaJ227RJecqE9MM9tvfQ=; b=ENpCl5jHTzOrnNJ4YZXd565U4QX/gBqHknO3U2sbR5tDeaMscAEJK7VoSM9eOfwqwf xFPYfP8XzqnrF+7SIgXOwLK+nz7Ac1WmlXBVFA+jAwfebLHglDl3ciCV7rAJiBZvsy2J xNOSsBBmSJEOZee1Rj5RSNWg1QLWKPnhCGmQ+/u1IVvp1gItTT0g3a397hOXi/9JX5Qu IzaguCDZ1rmR78jsTemTtE68w2eNd/ATuycYURB8xcfLIaLJb+3DtRLiGxRPSme2iO+2 OQoBprqnnieCpi8Dg95zMXf8X0e01dq4N4z2lijcU1y1i5INGJp4SDCGHWVm1Z1W5A2H Q/jg==; darn=lists.php.net ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1769187024; x=1769791824; darn=lists.php.net; h=content-transfer-encoding:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=9n/swwelPOu2dShui6uF2pd742fw31/9wMx5nkLry1g=; b=BRjIhKnmUeaBstLSBlcT28A3Bh3FMtLfC85+9nIWa+S3ROFkAo9c0VGz7qQzpxuwH6 tDc392RG89m6/lzY5Kz2602uMl+k3mx4uaCT3LzUw76E9jX3LPwXNIuTU7+/U8Zjaa9o /zIN2NAbpOijMzI2HUmCoNhgEaTGNTmsHhmje18qHhr3/NExsmeO8rr0sOWuBMkGk0k+ n3NYM73Q7th/vgqcRt8dU56Z4jT1kEnMySwcTAtcniFHOz4jgtxsn+zhh3//1+UWCLSR D0yhMbBBeWleEAqihOWXE3kiOSyzZEsLZpCx/r6Js55Yqk1bja6iFzUWrGgDDYk09RmN 8jMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769187024; x=1769791824; h=content-transfer-encoding:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=9n/swwelPOu2dShui6uF2pd742fw31/9wMx5nkLry1g=; b=WBaMV6WjReNf13+UyGCJpLsKVvOiS1lnKr22K2woj52lA3ilH37jQ9oYzst+EEXK+k DzTUxG3bEEFFjOI8jasmnw2MptsiG1YECs4zavXw5Tr7pRZwFdECLHnc9DHnOLRE691A fprQe7UxB8+/RVwjdG4mx8hKyARHHsxF/5qX6AkkFYozm6QcreUULqLUiwN1o7VkfMH4 JMam/Qi4mgZtBzMPAv5HkIwVFuykKNXp9gDD9wULUcGFhF70DdVzlpYi+mmDBB3eSV9q E7XjwBaomSRxNMqQ2qsXz+CsHXP29U5CSzKiWx1Go7qRDkdP8qRYYIEc7/OKYZ5XV8tg tCyA== X-Gm-Message-State: AOJu0YxmpjiJSvsoG4T4zuSmsDDCepURc9xPGYfE/4lu/FFyz0FLM9hu 2DdOsBZ+qws28rYeOvfLfzcwhjCyO4WvJeinMgYPlhTQVln3OVSyyTXLgCaQFTi3nqf+qfjOGEz 3zc8P/99xwKoj8uLUQVoeD7SaED1uDEhZ3cXE8tzstA== X-Gm-Gg: AZuq6aLWchwr6ILCd8sxWsalOrQNSamKBCtJ4kERqKjnYGN8fJKlUJ3YSDyPfeMmtj4 xwKoKmunqJeSG0HZ9c5Qz1uHuW+vyMWNArSXmgvrYCYUAzVv+gDlhhACFuHLERtQ/ZQ/CEAYk+Q Gm8DWKye6pj7bu6tiNiB9pdTIfs2T2/i5/pbSqlf6ge29FG8wLB3I/PSnuCZ4c43j+f/hU/3zXj ZO2UJ/979FTcxfkx5eUesFyGY/oVQ3/2wMDk9z/nD7YV+JL8wzrgM09Vv5r9zAJcqnbsKnsng== X-Received: by 2002:a05:6214:20a8:b0:894:562d:c0b9 with SMTP id 6a1803df08f44-894900d11admr52163836d6.0.1769187024431; Fri, 23 Jan 2026 08:50:24 -0800 (PST) Precedence: list list-help: list-unsubscribe: list-post: List-Id: x-ms-reactions: disallow MIME-Version: 1.0 References: <7562c18a-e0e4-4af5-aca1-bea0a7078c7b@app.fastmail.com> In-Reply-To: <7562c18a-e0e4-4af5-aca1-bea0a7078c7b@app.fastmail.com> Date: Fri, 23 Jan 2026 17:50:13 +0100 X-Gm-Features: AZwV_QjtzAiS6z8seQceHSt5x-cgXFqQ6ssyJYr9WmEwy2PqYOUpTeeQM2r-Nc4 Message-ID: Subject: Re: [PHP-DEV] Closure optimizations To: php internals Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable From: tovilo.ilija@gmail.com (Ilija Tovilo) Hi Larry On Thu, Jan 22, 2026 at 6:19=E2=80=AFPM Larry Garfield wrote: > > On Thu, Jan 22, 2026, at 10:41 AM, Ilija Tovilo wrote: > > > > As mentioned, the rules for when static can be inferred are slightly > > esoteric. For example, your code may be calling Foo::bar(), which > > _looks_ like a static call, but could actually be an instance > > grand-parent call (https://3v4l.org/uDi8W#v8.4.14). If you were to > > remove this ambiguous call, and the closure could now be inferred as > > static, it would be bad if existing Closure::bind[To]() calls would > > break because they provide an object. For this reason, > > Closure::bind[To]() will _accept but discard_ objects only for > > closures inferred as static. > > Ah, so it's just a "don't break code that's already wrong but not harmful= ly so" feature. I wouldn't consider it wrong to not mark functions as static that could be static, otherwise there wouldn't be a need for this optimization. Consequently, it would also not be wrong to attempt to Closure::bind() an object to such a closure, which is why I felt it was important to keep this case working. The caveat here being that the object is discarded, so ReflectionFunction::getClosureThis() will still return NULL. > I'm OK with that, but please add that to the RFC. I did not plan to make an RFC for this, given the BC breaks are mostly theoretical. But if anybody objects, I'm happy to create one. Ilija On Thu, Jan 22, 2026 at 6:19=E2=80=AFPM Larry Garfield wrote: > > On Thu, Jan 22, 2026, at 10:41 AM, Ilija Tovilo wrote: > > Hi Larry > > > > On Thu, Jan 22, 2026 at 5:03=E2=80=AFPM Larry Garfield wrote: > >> > >> On Wed, Jan 21, 2026, at 1:52 PM, Ilija Tovilo wrote: > >> > > >> > I've created a PR implementing two new optimizations for closures. [= 1] > >> > There are some theoretical BC breaks, so please let me know if any o= f > >> > them are of concern to you. > >> > > >> > Of note is that Closure::bind() and Closure::bindTo() usually throw > >> > when attempting to bind an object to a static closure. In my PR, thi= s > >> > is explicitly allowed only for closures that are inferred as static, > >> > but not those that are explicitly static. > >> > > >> > > >> > [1] https://github.com/php/php-src/pull/19941 > >> > >> This all looks great, Ilija! I am not concerned about the BC mentions= , as they seem to be accurate anyway. > >> > >> My one question is about the bindTo() on an inferred static closure. = What purpose does that serve? I'm assuming that anything that mentions $th= is in its body won't be marked static, and if it doesn't have $this I don't= get what value bindTo() would have. What's the use case for making an exc= eption here? > > > > Oops, it seems I've left out some details I was meaning to add. The > > aim for allowing the passing of objects to Closure::bind[To]() is to > > retain BC when a closure can suddenly be inferred as static due to > > seemingly unrelated changes. > > > > As mentioned, the rules for when static can be inferred are slightly > > esoteric. For example, your code may be calling Foo::bar(), which > > _looks_ like a static call, but could actually be an instance > > grand-parent call (https://3v4l.org/uDi8W#v8.4.14). If you were to > > remove this ambiguous call, and the closure could now be inferred as > > static, it would be bad if existing Closure::bind[To]() calls would > > break because they provide an object. For this reason, > > Closure::bind[To]() will _accept but discard_ objects only for > > closures inferred as static. > > > > Ilija > > Ah, so it's just a "don't break code that's already wrong but not harmful= ly so" feature. I'm OK with that, but please add that to the RFC. > > --Larry Garfield