Skip to content

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

Open

Description

@janbarasek

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.

Activity

  1. changed the title [-]Function preg_match() function should not be used instead of str_*[/-] [+]Function preg_match() should not be used instead of str_*[/+] on Jan 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions