Skip to content

PregQuoteUsage ​

error on by default

Group: Probable bugs · PhpStorm name: PregQuoteUsageInspection

preg_quote() only escapes the pattern delimiter when it is given as the second argument. Called with a single argument, a / or # inside the quoted text breaks the surrounding pattern.

Example ​

php
<?php
$re1 = '~' . preg_quote($needle) . '~i';
$re2 = preg_quote ( $host );
$re3 = '@^' . preg_quote($path, '@') . '$@';
$re4 = $quoter->preg_quote($needle);

Reported:

  • line 2: Pass the pattern delimiter to preg_quote() as its second argument.
  • line 3: Pass the pattern delimiter to preg_quote() as its second argument.

Configure ​

In custos.json:

json
{
  "rules": {
    "PregQuoteUsage": {
      "enabled": false
    }
  }
}

Suppress ​

Before the statement or declaration (or the first statement of the file), either of:

php
// @custos-ignore PregQuoteUsage

/**
 * @noinspection PregQuoteUsageInspection
 */

Released under the MIT License. Rule catalogue modelled on Php Inspections (EA Extended); independent clean-room implementation.