Squiz.PHP.EmbeddedPhp.ContentAfterEnd and DOCTYPE

Author: kkmuffmeCreated Jan 24, 2023Updated Mar 9, 2026

Describe the bug

Code sample

php
?><!DOCTYPE html>

Custom ruleset

xml
<?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
php
?>
<!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):

  • OS: Centos 8
  • PHP: 7.4
  • PHPCS: master
  • Standard: custom

Source: squizlabs/PHP_CodeSniffer