Skip to content

Bug with mixture of php with comments and html #2419

Description

@dmitryostrov

Prettier 3.5.3

PHP Plugin 0.22.4

# Options (if any):

Input:

<?php
const a = true;
?><div></div>
<?php if (2==2) {
  // comment
  ?><span></span><?php
  return true;
}

Output:

<?php
const a = true; ?><div></div>
<?php if (2 == 2) {<?php
    // comment
    ?><span></span><?php return true;}

Expected behavior:
< ? php above the comment line at the end is not needed

Activity

  1. vfrunza commented on Apr 2, 2025

    @vfrunza

    I ran into the same issue yesturday.

    <?php
    if ($add_call || $edit_call){
            ?>
    
    <?php
    	}  elseif ($add_call || $edit_call) {
     	  // ADD EDIT CALL NOTE form
    ?>
         <h1> Call Header </h1>
    <?php
    }
    ?>
    

    That snippit will format to this:

    <?php
    if ($add_call || $edit_call) { ?>
    <?php } elseif ($add_call || $edit_call) {<?php
        // ADD EDIT CALL NOTE form
        ?>
         <h1> Call Header </h1>
    <?php } ?>
    
  2. hackel commented on Jun 2, 2025

    @hackel
    Contributor

    From README:

    Formatting of files that contain mixed PHP and HTML is still considered unstable

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions