[BUG] Frequently adds comments that break PHP variables/echo statements by injecting words with apostrophes.

Resolved 💬 5 comments Opened Jul 4, 2025 by ddgconsultant Closed Nov 30, 2025

Environment

  • Platform (select one):
  • [ ] Anthropic API
  • [ ] AWS Bedrock
  • [ ] Google Vertex AI
  • [X] Other: Code
  • Claude CLI version: Opus
  • Operating System: Any
  • Terminal: Any

Bug Description

Claude frequently inserts inline comments containing words with apostrophes (like "it's", "don't", "won't") within PHP code, which breaks syntax when these comments are placed inside single-quoted strings or echo statements. This causes PHP parse errors due to unescaped apostrophes conflicting with the string delimiters.

Steps to Reproduce

  1. Ask Claude to modify or generate PHP code containing echo statements or variable assignments
  2. Claude adds helpful inline comments explaining the code
  3. Comments often contain contractions or possessive forms with apostrophes
  4. These apostrophes break the PHP syntax when placed within single-quoted contexts

Example prompt: "Add logging to this PHP function"

function processUser($id) {
    echo 'Processing user';
    return $id;
}

Expected Behavior

Claude should either:

  • Use double quotes for strings when adding comments with apostrophes
  • Escape apostrophes in comments within single-quoted contexts
  • Place comments outside of string literals
  • Avoid contractions in inline comments within PHP strings

Actual Behavior

Claude generates code like:

function processUser($id) {
    echo 'Processing user // Let's log the user's ID';  // Breaks due to unescaped apostrophes
    echo 'Status: Ready // It's important to track this';  // Parse error
    return $id;
}

Results in: PHP Parse error: syntax error, unexpected 's' (T_STRING)

Additional Context

This issue occurs most frequently when:

  • Claude adds explanatory comments to existing code
  • Working with legacy PHP code that uses single quotes extensively
  • Claude tries to be helpful by explaining what code does inline

Workaround: Explicitly request "no inline comments" or "use double quotes for all strings" when working with PHP code.

View original on GitHub ↗

This issue has 5 comments on GitHub. Read the full discussion on GitHub ↗