When formatting a PHP file with a shebang, the formatted moves the opening PHP tag to the same line as the shebang.

Example:

#!/usr/bin/env php
<?php

echo "Hello, world!\n";

What's happening:

#!/usr/bin/env php <?php

echo "Hello, world!\n";

Expected:

#!/usr/bin/env php
<?php

echo "Hello, world!\n";

VSCode:

Version: 1.96.4 (Universal)
Commit: cd4ee3b1c348a13bafd8f9ad8060705f6d4b9cba
Date: 2025-01-16T00:16:19.038Z
Electron: 32.2.6
ElectronBuildId: 10629634
Chromium: 128.0.6613.186
Node.js: 20.18.1
V8: 12.8.374.38-electron.0
OS: Darwin arm64 24.1.0

Extension: 1.55.16685

    Hello,

    Thank you for reporting this. However, I'm not able to reproduce. Maybe it's related to a specific formatting rule. Could you please send us the formatting settings options that you use?

    Thank you

      {
          "php.format.rules.addCommaAfterLastArrayElement": true,
          "php.format.rules.addCommaAfterLastCallParameter": true,
          "php.format.rules.addCommaAfterLastDeclParameter": false,
          "php.format.rules.alignConsecutiveAssignments": false,
          "php.format.rules.alignConstants": false,
          "php.format.rules.alignEnumCases": false,
          "php.format.rules.alignMatchArmBodies": false,
          "php.format.rules.alignProperties": false,
          "php.format.rules.arrayInitializersAlignKeyValuePairs": false,
          "php.format.rules.arrayInitializersNewLineAfterLastElement": true,
          "php.format.rules.arrayInitializersNewLineBeforeFirstElement": true,
          "php.format.rules.arrayInitializersWrap": "onEveryItem",
          "php.format.rules.blankLinesAfterClass": 0,
          "php.format.rules.blankLinesAfterClassBody": 0,
          "php.format.rules.blankLinesAfterFunction": 1,
          "php.format.rules.blankLinesAfterMethod": 1,
          "php.format.rules.blankLinesAfterNamespace": 1,
          "php.format.rules.blankLinesAfterOpenTag": 1,
          "php.format.rules.blankLinesAfterUseStatements": 1,
          "php.format.rules.blankLinesBeforeClass": 1,
          "php.format.rules.blankLinesBeforeClassBody": 0,
          "php.format.rules.blankLinesBeforeFunction": 1,
          "php.format.rules.blankLinesBeforeFunctionBody": 0,
          "php.format.rules.blankLinesBeforeMethod": 1,
          "php.format.rules.blankLinesBeforeMethodBody": 0,
          "php.format.rules.blankLinesBeforeNamespace": 1,
          "php.format.rules.blankLinesBeforeUseStatements": 1,
          "php.format.rules.blankLinesBetweenUseTypes": 1,
          "php.format.rules.booleanConstantCasing": "lowercase",
          "php.format.rules.callParametersNewLineAfterLeftParen": true,
          "php.format.rules.callParametersNewLineBeforeRightParen": true,
          "php.format.rules.callParametersWrap": "onEveryItem",
          "php.format.rules.catchOnNewLine": false,
          "php.format.rules.chainedMethodCallsSemicolonOnNewLine": false,
          "php.format.rules.chainedMethodCallsWrap": "always",
          "php.format.rules.declCompactEmptyBody": true,
          "php.format.rules.declKeepRightParenAndOpenBraceOnOneLine": true,
          "php.format.rules.declParametersNewLineAfterLeftParen": true,
          "php.format.rules.declParametersNewLineBeforeRightParen": true,
          "php.format.rules.declParametersWrap": "onEveryItem",
          "php.format.rules.elseOnNewLine": false,
          "php.format.rules.endWithNewLine": true,
          "php.format.rules.finallyOnNewLine": false,
          "php.format.rules.forStatementNewLineAfterLeftParen": true,
          "php.format.rules.forStatementNewLineBeforeRightParen": true,
          "php.format.rules.forStatementWrap": "onEveryItem",
          "php.format.rules.groupUseNewLineBeforeFirstDeclaration": true,
          "php.format.rules.groupUseWrap": "onEveryItem",
          "php.format.rules.ifStatementNewLineAfterLeftParen": true,
          "php.format.rules.ifStatementNewLineBeforeRightParen": true,
          "php.format.rules.implementsListWrap": "onEveryItem",
          "php.format.rules.indentBraces": false,
          "php.format.rules.indentHeredoc": true,
          "php.format.rules.inlineHeredoc": true,
          "php.format.rules.keepClassesOnOneLine": false,
          "php.format.rules.keepControlStatementsOnOneLine": false,
          "php.format.rules.keepFunctionsOnOneLine": false,
          "php.format.rules.maxBlankLines": 1,
          "php.format.rules.newLineAfterImplements": true,
          "php.format.rules.nullConstantCasing": "lowercase",
          "php.format.rules.openBraceOnNewLineForAnonymousClasses": false,
          "php.format.rules.openBraceOnNewLineForBlocks": false,
          "php.format.rules.openBraceOnNewLineForFunctions": true,
          "php.format.rules.openBraceOnNewLineForLambdas": false,
          "php.format.rules.openBraceOnNewLineForNamespaces": false,
          "php.format.rules.openBraceOnNewLineForTypes": true,
          "php.format.rules.spaceAfterCast": true,
          "php.format.rules.spaceAfterUnaryNot": false,
          "php.format.rules.spaceAroundConcatenation": true,
          "php.format.rules.spaceBeforeColonInControlStatements": false,
          "php.format.rules.spaceBeforeColonInReturnType": false,
          "php.format.rules.spaceBeforeParenthesesInArrowFunctions": true,
          "php.format.rules.spaceBeforeParenthesesInCalls": false,
          "php.format.rules.spaceBeforeParenthesesInControlStatements": true,
          "php.format.rules.spaceBeforeParenthesesInDeclarations": false,
          "php.format.rules.spaceWithinArrayInitilizersParens": false,
          "php.format.rules.spaceWithinBrackets": false,
          "php.format.rules.spaceWithinBracketsAroundExpression": false,
          "php.format.rules.spaceWithinCallParens": false,
          "php.format.rules.spaceWithinCatchParens": false,
          "php.format.rules.spaceWithinDeclParens": false,
          "php.format.rules.spaceWithinExpressionParens": false,
          "php.format.rules.spaceWithinForParens": false,
          "php.format.rules.spaceWithinForeachParens": false,
          "php.format.rules.spaceWithinIfParens": false,
          "php.format.rules.spaceWithinSwitchParens": false,
          "php.format.rules.spaceWithinWhileParens": false,
          "php.format.rules.switchStatementNewLineAfterLeftParen": true,
          "php.format.rules.switchStatementNewLineBeforeRightParen": true,
          "php.format.rules.whileStatementNewLineAfterLeftParen": true,
          "php.format.rules.whileStatementNewLineBeforeRightParen": true
      }

        Thank you, we are still not able to reproduce :-/

        So I'm thinking whether it's an interaction with another extension or maybe formatting settings specific to HTML? Could you please list those too (Extensions, and HTML format settings)?

          Write a Reply...