// Annoyingly, preg_match would not warn about the `/e` modifier, removed in php 7.
// Use `preg_replace` instead (The eval body is empty and phan requires 7.0+ to run)
$result=@\preg_replace($pattern,'','');
if(!\is_string($result)){
return\error_get_last()??[];
}
returnnull;
}finally{
\ob_end_clean();
\error_reporting($old_error_reporting);
}
});
if($err!==null){
// TODO: scan for 'at offset %d$' and print the corresponding section of the regex. Note: Have to remove delimiters and unescape characters within the delimiters.
self::emitIssue(
$code_base,
$context,
'PhanPluginInvalidPregRegex',
'Call to {FUNCTION} was passed an invalid regex {STRING_LITERAL}: {DETAILS}',
yield['PhanPluginPregRegexDollarAllowsNewline','Call to {FUNCTION} used \'$\' in {STRING_LITERAL}, which allows a newline character \'\n\' before the end of the string. Add D to qualifiers to forbid the newline, m to match any newline, or suppress this issue if this is deliberate'];
}
}
}
/**
* Tokenize the regex, using imperfect heuristics to split up the parts of a regular expression.