squizlabs / PHP_CodeSniffer

PHP_CodeSniffer tokenizes PHP files and detects violations of a defined set of coding standards.
BSD 3-Clause "New" or "Revised" License
10.67k stars 1.48k forks source link

Squiz.PHP.EmbeddedPhp.ContentAfterEnd and DOCTYPE #3747

Open kkmuffme opened 1 year ago

kkmuffme commented 1 year ago

Describe the bug

Code sample

?><!DOCTYPE html>

Custom ruleset

<?xml version="1.0"?>
<ruleset name="My Custom Standard">
  <description>If you are using a custom ruleset, please enter it here.</description>
  <rule ref="Squiz.PHP.EmbeddedPhp.ContentAfterEnd"/>
</ruleset>

To reproduce Steps to reproduce the behavior:

  1. Create a file called test.php with the code sample above...
  2. Run phpcbf test.php ...
  3. phpcbf created invalid HTML
    ?>
    <!DOCTYPE html>

Expected behavior There is no space allowed before the DOCTYPE tag - any space before the DOCTYPE will cause browsers to run quirks mode.

Versions (please complete the following information):