Menu

← Back to argument.*

Error Identifier: argument.invalidPregQuote

Every error reported by PHPStan has an error identifier. Here’s a list of all error identifiers. In PHPStan Pro you can see the error identifier next to each error and filter errors by their identifiers.

Code example #

<?php declare(strict_types = 1);

$delimiter = '/';
$pattern = '/' . preg_quote($input) . '/';

Why is it reported? #

The call to preg_quote() is missing the delimiter parameter or uses an incorrect delimiter. preg_quote() escapes special regex characters, but it needs to know the delimiter character to escape it as well. Without the correct delimiter parameter, the quoted string may still contain unescaped delimiter characters, which will break the regular expression.

In the example above, the pattern uses / as the delimiter, but preg_quote() is called without specifying this delimiter as the second argument.

How to fix it #

Pass the correct delimiter as the second argument to preg_quote():

 <?php declare(strict_types = 1);
 
 $delimiter = '/';
-$pattern = '/' . preg_quote($input) . '/';
+$pattern = '/' . preg_quote($input, '/') . '/';

How to ignore this error #

You can use the identifier argument.invalidPregQuote to ignore this error using a comment:

// @phpstan-ignore argument.invalidPregQuote
codeThatProducesTheError();

You can also use only the identifier key to ignore all errors of the same type in your configuration file in the ignoreErrors parameter:

parameters:
	ignoreErrors:
		-
			identifier: argument.invalidPregQuote

Rules that report this error #

  • PHPStan\Rules\Regexp\RegularExpressionQuotingRule [1] [2] [3] [4]

Edit this page on GitHub

Theme
A
© 2026 PHPStan s.r.o.