Skip to content

mago could warn about the use of preg_replace with explode would suffice #1554

@UweOhse

Description

@UweOhse

Feature

I'd like mago to warn about the use of preg_split when explode would suffice: When flags is 0, and the string content doesn't contain any of the special chars preg_quote escapes: \ + * ? [ ^ ] $ ( ) { } = ! < > | : - #

Ideally it could also offer a fixer for that, but a warning alone would be very useful for me. I've got 20 years of regex abuse to clean up :-)

Example

<?php
# Example where it should warn.

$csvline="1, 2, 3, 4, 99";
foreach (preg_split("/, /",$csvline) as $k=>$v) {
   print "#$k = $v\n";
}

Metadata

Metadata

Assignees

Labels

c-linterPHP linting for errors, style, and bugst-enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions