Sabuj Kundu 9th Nov 2025

Short version: Use // phpcs:disable and // phpcs:enable for blocks, // phpcs:ignore for a single line, and // phpcs:ignoreFile to ignore a whole file. You can also target specific sniffs or categories.

Why you might ignore PHPCS

PHPCS (PHP_CodeSniffer) is strict by design. Sometimes you have legacy code, generated code, or a one-off pattern where fixing the warning is impractical or risky.
In those cases, temporary, targeted suppression helps keep the rest of your codebase clean while acknowledging the exception.

Basic syntaxes (PHP comment style)

These work inside PHP files (use the matching comment style in other languages, e.g. /* … */ for block comments in CSS/JS if needed).

Ignore a single line

// phpcs:ignore
$foo = $_POST['foo']; // phpcs:ignore

Or target a specific sniff (recommended instead of ignoring everything):

// phpcs:ignore Squiz.Security.Eval
eval($userProvided); // phpcs:ignore Squiz.Security.Eval

Disable/enable a block

// phpcs:disable
// everything between these lines is ignored by PHPCS
$xml->something = 'legacy';
// phpcs:enable

You can also disable only specific sniffs for the block:

// phpcs:disable Generic.Commenting.Todo.Found
// TODO: maintainers will fill this later
// phpcs:enable Generic.Commenting.Todo.Found

Ignore an entire file

// phpcs:ignoreFile
<?php
// phpcs will not report anything from this file

Inline ignore for one expression only

$value = some_long_call( /* phpcs:ignore Squiz.Arrays.ArrayDeclaration.SingleLineNotAllowed */ );

Legacy markers you may still see

Older code and older PHPCS versions used the @codingStandardsIgnoreStart / @codingStandardsIgnoreEnd (and @codingStandardsIgnoreFile) markers.
These were deprecated in PHPCS >= 3.2.0 in favor of the phpcs: style (and the old markers are scheduled for removal in PHPCS v4). Prefer the phpcs: comments in current projects.

// legacy style (deprecated)
 // @codingStandardsIgnoreStart
 // ... old code ...
 // @codingStandardsIgnoreEnd

Selective disabling: target specific sniffs, categories, or standards

Instead of silencing all checks, prefer to disable only the specific sniff(s) that are noisy and impossible-to-fix right now.
You can pass a list of sniff identifiers, categories, or even whole standards.

// phpcs:disable Squiz.Arrays.ArrayDeclaration.SingleLineNotAllowed
$foo = [1,2,3];
// phpcs:enable Squiz.Arrays.ArrayDeclaration.SingleLineNotAllowed

// multiple targets
// phpcs:disable PEAR,Squiz.Arrays
$foo = [1,2,3];
// phpcs:enable

Selective disabling is supported from PHPCS 3.2.0 and later — it allows much finer control than the old @codingStandards comments.

Tips, pitfalls and best practices

  • Prefer minimal scope: use single-line ignores or targeted sniff names rather than disabling a whole block.
  • Document why: add a short comment explaining why the rule is ignored so future maintainers can assess necessity.
  • Avoid file-wide ignores unless absolutely necessary. They hide problems across the entire file.
  • Watch ordering: multiple phpcs:enable comments can interact in surprising ways; keep enables/disables well-structured. Issues have been reported where enables sometimes override later ignores when used inconsistently.
  • Update old markers: if your project still uses @codingStandardsIgnoreStart / @codingStandardsIgnoreEnd, migrate to phpcs:disable / phpcs:enable to remain compatible with modern PHPCS versions.

Complete example — legacy + modern, with reason

// phpcs:disable Generic.Commenting.Todo.Found
// Reason: heavy legacy section, will refactor later (ticket #1234)
// The TODOs here are intentionally left for the refactor branch.
function legacy_process()
{
    // lots of legacy logic
}
// phpcs:enable Generic.Commenting.Todo.Found

Short checklist: prefer phpcs:ignore for one line, phpcs:disable / phpcs:enable for blocks, and target specific sniff names whenever possible. Keep notes so your future self (or a teammate) can revert the ignore when the code is cleaned up.

Need to build a Website or Application?

Since 2011, Codeboxr has been transforming client visions into powerful, user-friendly web experiences. We specialize in building bespoke web applications that drive growth and engagement.

Our deep expertise in modern technologies like Laravel and Flutter allows us to create robust, scalable solutions from the ground up. As WordPress veterans, we also excel at crafting high-performance websites and developing advanced custom plugins that extend functionality perfectly to your needs.

Let’s build the advanced web solution your business demands.