website/errors/argument.invalidPregQuote.md
<?php declare(strict_types = 1);
function foo(string $input): void {
preg_match("/" . preg_quote($input) . "/", "test");
}
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.
Pass the correct delimiter as the second argument to preg_quote():
<?php declare(strict_types = 1);
function foo(string $input): void {
- preg_match("/" . preg_quote($input) . "/", "test");
+ preg_match("/" . preg_quote($input, "/") . "/", "test");
}