Skip to content

Lexer: ?> inside a // line comment does not end PHP mode #447

Closed

Description

@blacktrs

In PHP, a single-line comment (// or #) ends at a newline or at ?>; the close tag then switches to inline HTML. Manticore appears to treat the whole line as a comment and keeps compiling the file as PHP.

Found in manticore-fmt: src/Rule/ControlStructureBraces.php (before the fix) had

// getPrevNonWhitespace: the last comment of the gap before `?>`, else the token before it

Zend reads ?> there as T_CLOSE_TAG and the rest of the line as inline HTML. Manticore compiled the file without complaint, so the divergence only surfaced when manticore-fmt (which follows PHP semantics) formatted it and put blank lines before <?php, changing the output of the built binary.

Expected: either follow PHP (end PHP mode at ?> in a line comment) or report a diagnostic for a source whose ?> inside a line comment changes how Zend would read it.

Repro:

<?php
// see `?>` here
echo "x\n";

php prints here\n as inline HTML and then x is not executed as PHP... (the line after ?> is HTML text, echo is output verbatim). Manticore runs the echo.

Activity

  1. blacktrs commented on Oct 26, 2026

    @blacktrs
    ContributorAuthor

    Fixed in cd3558d (merged via PR #461).

  2. added a commit that references this issue on Oct 26, 2026
    5845b2b
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