Skip to content

PRISM drops a PHP heredoc's newlines: every function after one reports the wrong start_line #3555

Closed

Description

@squid-protocol

Problem

PRISM's PHP code_stream collapses a heredoc or nowdoc (<<<EOD … EOD;) to "" and removes its newlines. So every line number after a heredoc is shifted, including start_line/end_line for every later function, SARIF locations, and anything that anchors on lines.

Minimal repro:

src = "<?php\nfunction a() {\n $x = <<<EOD\nline1\nline2\nline3\nEOD;\n}\nfunction b() {}\n"
code = Prism(LEXICAL_FAMILY_HEURISTICS, LANGUAGE_DEFINITIONS).split_streams(src, "php")["code_stream"]
# code == '<?php\nfunction a() {\n $x = ""\n}\nfunction b() {}\n'  -- 9 newlines in, 5 out
# splice(): b reported at line 4; it is on line 9

On the corpus, php/wordpress/functions.php has 9284 raw lines but only 9274 in its code stream. Every function after the heredoc at line 4238 (_xml_wp_die_handler) reports a start_line 10-11 lines early; _scalar_wp_die_handler is the first.

I checked 16 other languages' multi-line string forms: Ruby/Perl/shell heredocs, Python/Kotlin/Swift/Scala/Java triple-quoted strings, JS/TS template literals, Go raw strings, Rust raw strings, C# verbatim strings, C++ raw strings, Lua long brackets and Dart '''. None lose lines. This is PHP-only.

Impact

Fix direction

Make PRISM's PHP heredoc/nowdoc shield preserve the newline count: replace the body with "" followed by the same number of \n, or blank each body line as other languages' multi-line shields do. Check with raw.count("\n") == code_stream.count("\n") on wordpress/functions.php. Re-bless the golden masters; expect PHP start_line/end_line moves only, after heredocs.

Activity

  1. added
    bug
    core-engine
    on Sep 25, 2026
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

    bugcore-engine

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions