Skip to content

Preserve heredoc/nowdoc formatting #1007

@theofidry

Description

@theofidry

Whilst upgrading PHP-Scoper to PHP-Parser 5, I've run into the issue of sebastianbergmann/phpunit#5855.

This is caused by this change:

For PHP >= 7.3 (default), heredoc/nowdoc strings are now indented just like regular code. This was allowed with the introduction of flexible heredoc/nowdoc strings.

Previously the parser was preserving the formatting while possible, this does not seem to be the case anymore. I assume this was a deliberate change in the printer to simplify it and keep the old behaviour with Printer::printFormatPreserving().

With PHP-Scoper however, I very easily run into the issue of the printer bailing out (if preserving format), which to be honest is too surprising considering the changes to the AST are not small (you can find plenty of examples here, but the gist of it is, changing names, adding namespaces and class_alias() statements or function_exists() statements.).

Is printFormatPreserving() the way to go in which case more fixing needs to be done to the printer or is there another way?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions