website/errors/regexp.pattern.md
<?php declare(strict_types = 1);
$result = preg_match('/[unclosed/', 'test');
The regular expression pattern passed to a preg_* function is invalid and would produce a warning or error at runtime. PHP's PCRE engine cannot compile the pattern, which means the function call will fail. PHPStan validates regex patterns at analysis time when they can be statically resolved.
Common causes include missing closing delimiters, unmatched brackets, invalid escape sequences, and other PCRE syntax errors.
Correct the regular expression syntax:
<?php declare(strict_types = 1);
-$result = preg_match('/[unclosed/', 'test');
+$result = preg_match('/\[unclosed/', 'test');
Or if the intent was a character class, close the bracket:
<?php declare(strict_types = 1);
-$result = preg_match('/[unclosed/', 'test');
+$result = preg_match('/[unclosed]/', 'test');
Test the corrected pattern using a tool like regex101 to verify it matches the intended strings before applying the fix.