vscode-phpfmt icon indicating copy to clipboard operation
vscode-phpfmt copied to clipboard

Formatting error when type hinting class properties in PHP 8

Open murugappanrm opened this issue 3 years ago • 7 comments

This is my code:

<?php

declare (strict_types = 1);

class Transaction
{
  public int $test = 10;
}

After saving the file, the formatter formats the$test property wrongly:

<?php

declare (strict_types = 1);

class Transaction
{
 intpublic $test = 10;
}

murugappanrm avatar May 05 '22 03:05 murugappanrm

Hi, Is there any resolution to the problem? This bug is making the usefulness of VS Code Editor to become less.

murugappanrm avatar May 21 '22 13:05 murugappanrm

The current version of phpfmt does not support class property type hinting. You will need to use a different PHP formatter. I recommend trying PHP Tools extension by DEVSENSE, it provides basic code formatting, IntelliSense and some more features.

Jphn avatar Jun 13 '22 02:06 Jphn

Just add "phpfmt.psr2": false, in your settings.json file

cobraprojects avatar Jul 23 '22 04:07 cobraprojects

@cobraprojects I have set the setting as in the attached screen cap. Is that ok?

Screenshot_1

murugappanrm avatar Jul 24 '22 09:07 murugappanrm

Hi, Thank you for the update. I did that already but the only trouble is Devsense seems to have lots of problems with Codeigniter 4. So sad.

Regards from, Murugappan Ramanathan

On Monday, 13 June 2022 at 10:14:13 am MYT, João Pedro Holanda Neves ***@***.***> wrote:  

The current version of phpfmt does not support class property type hinting. You will need to use a different PHP formatter. I recommend trying PHP Tools extension by DEVSENSE, it provides basic code formation, IntelliSense and some more features.

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>

murugappanrm avatar Oct 11 '22 07:10 murugappanrm

For me issue was resolved by adding this to settings.json:

"phpfmt.exclude": [
    "PSR2ModifierVisibilityStaticOrder"
]

No need to disable whole PSR2 formatting.

TysiacSzescset avatar Oct 19 '22 13:10 TysiacSzescset

@TysiacSzescset after making changes as you suggested, it seems to be working now. Thank you.

murugappanrm avatar Oct 21 '22 02:10 murugappanrm

Hi folks,

I've made some PR to update PHPFMT package to a fresh version AND get oficial support to PHP8 https://github.com/kokororin/vscode-phpfmt/pull/101

lucasferreira avatar Mar 28 '23 18:03 lucasferreira