Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Function preg_match() should not be used instead of str_* #153

Open
janbarasek opened this issue Jan 16, 2022 · 0 comments
Open

Function preg_match() should not be used instead of str_* #153

janbarasek opened this issue Jan 16, 2022 · 0 comments

Comments

@janbarasek
Copy link

Hello,

I think the preg_match() function should not be used instead of the native str_* functions (PHP 8+).

Example:

if (preg_match('/\.\./', $path) === 1) { // bad, better is str_contains()
	throw new \InvalidArgumentException('Path "' . $path . '" could not contains \'..\'.');
}

This rule should apply to cases where the first argument to preg_match() is a string literal and also contains a string of ordinary characters that have no special meaning or have been escaped correctly (the string may be a valid input for str_*).

This improvement may help to better detect old places that are better to refactor.

Thank you.

@janbarasek janbarasek changed the title Function preg_match() function should not be used instead of str_* Function preg_match() should not be used instead of str_* Jan 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant