Page MenuHomePhabricator

Report PREG_REPLACE_EVAL as deprecated in codesniffer
Closed, ResolvedPublic


According to

 This feature was DEPRECATED in PHP 5.5.0, and REMOVED as of PHP 7.0.0.

So a /e should be reported by codesniffer as deprecated for php 7 (similar to other php7 things).

Possible way to do: Search for function call of preg_* (or only preg_replace?) and check the first argument (when it is a string) for e behind the regex separator (some regex are using #, so #find#e or #find#ie should be reported as well.

Event Timeline

Restricted Application added a subscriber: Aklapper. · View Herald TranscriptApr 6 2018, 10:40 PM

As of last week, this is now possible with built-in phan plugin (

thiemowmde triaged this task as Low priority.May 23 2018, 7:41 AM
thiemowmde added a subscriber: thiemowmde.

I totally support the idea of disallowing /e in any code. Unfortunately I can not think of a way to make this work in PHPCS. How would you detect this, for example?

$regex = ;
$regex .= '$e';
preg_replace( $regex,  );

Not only can the separation character be anything you like (you can even use pairs of brackets). Regular expressions containing the critical character 'e' are typically more complex, and typically constructed in some way.

If Phan can do it, please go for it!

Setting priority to low because I assume no sane code reviewer will accept code containing /e nowadays.

Change 493794 had a related patch set uploaded (by Daimona Eaytoy; owner: Daimona Eaytoy):
[mediawiki/tools/phan@master] Add RegexChecker and UnusedSuppression plugins

Daimona claimed this task.Mar 2 2019, 11:58 AM

Change 493794 merged by jenkins-bot:
[mediawiki/tools/phan@master] Add RegexChecker, UnusedSuppression and DuplicateExpression plugins

Daimona closed this task as Resolved.Mar 11 2019, 6:49 AM
Daimona removed a project: Patch-For-Review.

Done with phan.