From 630175127e9e39e3fb423dff7c62736c966c1512 Mon Sep 17 00:00:00 2001 From: Dextheking1 Date: Wed, 23 Sep 2026 14:06:17 +0200 Subject: [PATCH 1/5] fix: keep parens when calling the result of an assignment `($fn = function () {})`(...)` lost its parentheses: without them the call binds to the closure instead of the assignment result, producing invalid PHP. Closes prettier/plugin-php#2409 --- src/needs-parens.mjs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/needs-parens.mjs b/src/needs-parens.mjs index 2bd051fc0..5803925b4 100644 --- a/src/needs-parens.mjs +++ b/src/needs-parens.mjs @@ -179,7 +179,10 @@ function needsParens(path, options) { } else if (parent.kind === "silent") { return false; } else if (parent.kind === "call") { - return false; + // `($fn = function () {})()` needs the parentheses: without them + // the call binds to the closure instead of the assignment result. + // https://github.com/prettier/plugin-php/issues/2409 + return key === "what"; } return true; From 56e954067446d1608b54c9f51a4fa2374d742ddb Mon Sep 17 00:00:00 2001 From: Dextheking1 Date: Fri, 23 Oct 2026 04:07:58 +0200 Subject: [PATCH 2/5] test: cover parens when calling assignment result --- tests/assign-call/assign-call.php | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 tests/assign-call/assign-call.php diff --git a/tests/assign-call/assign-call.php b/tests/assign-call/assign-call.php new file mode 100644 index 000000000..019946d0e --- /dev/null +++ b/tests/assign-call/assign-call.php @@ -0,0 +1,10 @@ + 42)(); + +call($a = $b); From 45ae56b1a83fb3a20eb3c7f436bfc9c5f98e4209 Mon Sep 17 00:00:00 2001 From: Dextheking1 Date: Fri, 23 Oct 2026 04:08:00 +0200 Subject: [PATCH 3/5] test: cover parens when calling assignment result --- tests/assign-call/jsfmt.spec.mjs | 1 + 1 file changed, 1 insertion(+) create mode 100644 tests/assign-call/jsfmt.spec.mjs diff --git a/tests/assign-call/jsfmt.spec.mjs b/tests/assign-call/jsfmt.spec.mjs new file mode 100644 index 000000000..8829c872f --- /dev/null +++ b/tests/assign-call/jsfmt.spec.mjs @@ -0,0 +1 @@ +run_spec(import.meta, ["php"]); From 3a621bd8a2b6df5b72fd58e14ac42fe63ecd48ce Mon Sep 17 00:00:00 2001 From: Dextheking1 Date: Fri, 23 Oct 2026 04:08:02 +0200 Subject: [PATCH 4/5] test: cover parens when calling assignment result --- .../__snapshots__/jsfmt.spec.mjs.snap | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 tests/assign-call/__snapshots__/jsfmt.spec.mjs.snap diff --git a/tests/assign-call/__snapshots__/jsfmt.spec.mjs.snap b/tests/assign-call/__snapshots__/jsfmt.spec.mjs.snap new file mode 100644 index 000000000..439949cd8 --- /dev/null +++ b/tests/assign-call/__snapshots__/jsfmt.spec.mjs.snap @@ -0,0 +1,35 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`assign-call.php 1`] = ` +====================================options===================================== +parsers: ["php"] +printWidth: 80 + | printWidth +=====================================input====================================== + 42)(); + +call($a = $b); + +=====================================output===================================== + 42)(); + +call($a = $b); + +================================================================================ +`; From dff59f9f4174e8de472aefcebdcae12317f208e6 Mon Sep 17 00:00:00 2001 From: Dextheking1 Date: Fri, 23 Oct 2026 03:55:00 +0000 Subject: [PATCH 5/5] test: update assign-call snapshot header for jest 30 --- tests/assign-call/__snapshots__/jsfmt.spec.mjs.snap | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/assign-call/__snapshots__/jsfmt.spec.mjs.snap b/tests/assign-call/__snapshots__/jsfmt.spec.mjs.snap index 439949cd8..7ef47e3be 100644 --- a/tests/assign-call/__snapshots__/jsfmt.spec.mjs.snap +++ b/tests/assign-call/__snapshots__/jsfmt.spec.mjs.snap @@ -1,4 +1,4 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP +// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing exports[`assign-call.php 1`] = ` ====================================options=====================================