prettier / prettier/plugin-php

Brackets vanish in Recursive IIFE

Open
#2,277 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
PHP
Stars
1.9k
Forks
139
PR merge metrics
No merged PRs in 30d

Description

@prettier/plugin-php v0.21.0
Playground link

I took the code sample from https://stackoverflow.com/a/63649677/577052

Input:
This works in PHP 8.2

<?php
$arr = array();
($recursive = function (&$argument)
{
    global $recursive;

    if (count($argument) < 10)
    {
        $argument[] = 'foo';
        $recursive($argument);
    }
})($arr);
print_r($arr);



Output:
The pair of brackets is gone. Code does not work

<?php
$arr = [];
$recursive = function (&$argument) {
	global $recursive;

	if (count($argument) < 10) {
		$argument[] = 'foo';
		$recursive($argument);
	}
}($arr);
print_r($arr);

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue using the linked Playground example and compare the input with the formatted output. Investigate the plugin's formatting path for recursive immediately invoked functions; done means the brackets are preserved and the formatted PHP remains valid and executable.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.